Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * when creating a big float, there are two different constructors. The biggest difference I could see what the default precision for each:
- * `new(big.Float)` has a default precision of 0
- * `big.NewFloat` has a default precision of 53
- * this gets interesting when setting a either of these to a large number:
- * `new(big.Float)` seems to dynamically change the default precision to whatever is needed
- ```
- b := new(big.Float)
- b.SetUint64(16629421200200000000)
- //yields
- <*big.Float | 0xc0003ece10>: {
- prec: 64,
- mode: 0,
- acc: 0,
- form: 1,
- neg: false,
- mant: [16629421200200000000],
- exp: 64,
- }
- * `big.NewFloat` doesn’t seem to change the precision (unless done so explicitly)
- ```
- b := big.NewFloat(0.0)
- b.SetUint64(16629421200200000000)
- // yields
- <*big.Float | 0xc0003ece40>: {
- prec: 53,
- mode: 0,
- acc: -1,
- form: 1,
- neg: false,
- mant: [16629421200199999488],
- exp: 64,
- }
- ```
- * the `acc` (accuracy) attribute is -1, which represents `Below`
- * the `mant` attribute (the mantissa) is the value of the this float, which is less than the expected value
- * if we set the precision to 64 before calling `SetUint64` then we get the correct value
- ```
- b := big.NewFloat(0.0)
- b.SetPrec(64)
- b.SetUint64(16629421200200000000)
- // yields
- <*big.Float | 0xc000354090>: {
- prec: 64,
- mode: 0,
- acc: 0,
- form: 1,
- neg: false,
- mant: [16629421200200000000],
- exp: 64,
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement