cosmos72 / gomacro

Interactive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

corrupted const math values

mpl opened this issue · comments

Hi,

While playing with golang.org/x/tools/go/packages for Yaegi, we noticed that it produced pretty funky results when extracting symbols from the math pkg from the stdlib. Out of curiosity, we checked in your code, and we think you might be running into the same problem.

For example, look at the value for https://github.com/cosmos72/gomacro/blob/master/imports/math.go#L113 , with a bunch of zeroes right in the middle.

You don't seem to have as many obvious corruptions as we did, because you kept some of the expressions as divisions, but we advise all the more caution since they might be all the more hidden. We haven't had time to fully investigate the issue on our side.

Anyway, just a friendly heads up.

Cc: @mvertes

Thanks for the information!

The value of math.MaxFloat64 in Go source code is the untyped constant 1.797693134862315708145274237317043567981e+308.
I think the small rounding error in gomacro sources https://github.com/cosmos72/gomacro/blob/master/imports/math.go#L113 is acceptable: the relative error is 1e-155 i.e. the value has 155 correct digits when expressed in base 10.

Also, the original constant math.MaxFloat64 is only precise to 40 digits - it's not supposed to end with 268 zeroes. The exact value is stated in its comment: (1<<1023) * ((1<<53) - 1) / (1<<52) - which computes to 1.79769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368e+308

Thus gomacro preserves 155 correct digits of a constant which is itself precise only to 40 digits - more than enough.

And float64(math.MaxFloat64) returns the correct value.

I will keep my eyes open in case I find other constants with larger errors