-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Description
https://cs.opensource.google/go/go/+/master:src/math/big/float.go;l=309
Hopefully I'm not having a moment of stupidity, but the example for SetMantExp doesn't make sense to me:
// SetMantExp sets z to mant × 2**exp and returns z.
// The result z has the same precision and rounding mode
// as mant. SetMantExp is an inverse of MantExp but does
// not require 0.5 <= |mant| < 1.0. Specifically:
//
// mant := new(Float)
// new(Float).SetMantExp(mant, x.MantExp(mant)).Cmp(x) == 0
What is x here? I assume that it is an arbitrary *Float, although it would be good if that were stated explicitly.
This is saying that
mant := new(Float)
new(Float).SetMantExp(mant, x.MantExp(mant))
is equal to x (.Cmp(x) == 0).
new(Float).SetMantExp(mant, x.MantExp(mant)) looks like it should be a zero *Float since mant is a zero *Float. The exponent is set to the same as x (and mant is set to the mantissa of x although not used later) but that does not matter since the mantissa is zero. Based off my algebra skills from a long time ago, x should be a zero *Float then, to satisfy this example.
What exactly is this example supposed to demonstrate? If it is just demonstrating using a mantissa outside of [0.5, 1), I can think of many clearer examples.