Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: nerioseole on February 21, 2014, 02:27:34 AM



Title: How to access the calculated difficulty in the code?
Post by: nerioseole on February 21, 2014, 02:27:34 AM
I am experimenting with some new functions using the Bitcoin code.

I am in main.cpp and would like to do some arithmetic inside the code, using the value of the calculated Difficulty as one of the parameters (the same real value that shows when we ask  "getdifficulty" with the executable client).

I am sorry to say that I am not very good with C++, so I have a little of difficulty resolving the correct syntax. 

I came up with something like that to calculate the difficulty:

double dDiff = (double)0x0000ffff / (double)CBlockIndex* blockindex->nBits & 0x00ffffff;

But can't get it to compile.  Obviously my syntax is wrong... and I most likely not declaring some variables somewhere....

How should I write it?



Title: Re: How to access the calculated difficulty in the code?
Post by: -ck on February 22, 2014, 03:39:49 AM
Check out how I do it in cgminer with the set_blockdiff function

https://github.com/ckolivas/cgminer/blob/master/cgminer.c#L4302

ddiff is the calculated diff as a double