vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
985 stars 118 forks source link

Evaluate pi_ and other constants as floats #532

Open fllor opened 4 weeks ago

fllor commented 4 weeks ago

This PR addresses some issues discussed during the workshop.

Furthermore, this PR fixes a bug in the printing of floating point numbers, that could cause exponents to be truncated and memory errors that would be lead to warnings in valgrind.

coveralls commented 3 weeks ago

Coverage Status

coverage: 50.581% (+0.6%) from 49.999% when pulling 6880a65c8187736ca0d1e0a640fb4eed75c80760 on fllor:master into 83e3d4185efca2e5938c665a6df9d67d6d9492ca on vermaseren:master.

fllor commented 3 weeks ago

It seems the failure of the 32-bit tests might be due to a bug somewhere in the floating point engine. The program

#StartFloat 64

Local X = 2/3;
Local Y = sqrt_(3);
Local Z = pi_;

ToFloat;
Evaluate;

Print;
.end

gives me

X = 6.66666666666666666667e-01;
Y = 1.73205080756887729352e+00;
Z = 3.14159265358979323846e+00;

on my laptop and

X = 6.66666666666666666666666666667e-;
Y = 1.7320508075688772935274463415e+0;
Z = 3.14159265358979323846264338328e+;

on the 32-bit containers.

For some reason, floats are evaluated to a different precision. Also, note that Y in the first case is not rounded correctly. In the second case the exponents are not printed properly.

I am not sure if this is a bug in Form or GMP/MPFR. The internal representations are already different in evaluate.c:668.

jodavies commented 3 weeks ago

There is a known problem with the truncation of trailing zeros and messing up the exponent (see #492) which looks to be also the cause of the valgrind failures in your tests. So that needs to be sorted out but I didn't re-check it yet.

Jos said in his slides that float mode is not expected to work properly in 32bit mode, and it seems that it will be removed/declared "unsupported" for v5 anyway.

Once the valgrind errors are resolved you could also move your tests to features.frm rather than user-tests.frm.

fllor commented 3 weeks ago

Printing of exponents and valgrind errors should be fixed now. 32-bit tests will probably still fail.