Big floats precision getting worse

I’m trying to calculate the constants used for the SHA512 hash. But each iteration removes four hex digits and I’m not sure why. Any help or advice is appreciated! Let me know if something isn’t clear, and I’ll do my best to explain it better.

https://play.golang.org/p/HOedsCvYJXa

The first one is 428a2f98d728ae22. It can be found by taking the cube root of 2. Getting the mantissa/significand (ref:wikipedia). Then multiplying that by 16. This would give you 4, the first digit of the hex digit at the beginning of this paragraph. You then do this repeatedly until you’ve processed the first 64 bits.

These words represent the first sixty-four bits of the fractional parts of the cube roots of the first eighty prime numbers. In hex, these constant words are (from left to right)

Ref: FIPS 180-2.

1 Like

Floats are imprecise by nature, if they don’t suit your needs, you need to choose another datatype.

1 Like

Thanks for the reply. What datatype would be better?

1 Like

One that is precise enough for your purpose.

Perhaps try some fixed point implementations and play with the precision.

2 Likes

Could you please be more specific? I’m really not sure what to do.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.