Bitcoin Forum
June 30, 2024, 02:39:16 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Other / Bitcoin Wiki / Re: The Bitcoin Wiki Modernization Project - request changes and edits here on: July 19, 2021, 10:49:50 PM
I just have one minor change to propose, for the Difficulty calculation that's currently shown here: https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_calculated.3F_What_is_the_difference_between_bdiff_and_pdiff.3F

You can compute the difficulty in a much simpler manner, at least in C and C++.

Code:
#include <cmath>

double difficulty(const unsigned bits) {
  const unsigned exponent_diff  = 8 * (0x1D - ((bits >> 24) & 0xFF));
  const double significand = bits & 0xFFFFFF;
  return std::ldexp(0x00FFFF / significand, exponent_diff);
}

In C, just change cmath to math.h and std::ldexp to ldexp.

The ldexp() function lets you scale by a power of two almost for free, by directly adjusting the exponent on the floating point number.  Thus, the difficulty calculation gets reduced to a couple integer arithmetic steps, single floating point divide, and a single scale-by-power-of-2.

This should be quite a bit faster than what's currently on the Wiki, and it's far more direct.  No need for multiple floating point multiplies or an expensive floating point exponentiation.
2  Other / Bitcoin Wiki / Re: Request edit privileges here on: July 19, 2021, 12:14:11 AM
requesting edit privileges for "Mr z" on the wiki.
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!