Skip to content

Requires floating point excess precision on x86 with gcc #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pjsg opened this issue Sep 23, 2020 · 0 comments
Open

Requires floating point excess precision on x86 with gcc #7

pjsg opened this issue Sep 23, 2020 · 0 comments

Comments

@pjsg
Copy link

pjsg commented Sep 23, 2020

It turns out that the tests fail on linux on Intel if you add the following code:

void 
set_fpu (unsigned int mode)
{
  asm ("fldcw %0" : : "m" (*&mode));
}

and then

set_fpu(x27f);

at the start of main. This (according to https://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_70.html ) sets excess precision to be disabled. This makes it compatible with other platforms that do not support excess precision.

Indeed, the results that I then get from x86 compare to those that I get from a microcontroller platform.

The failed tests seem to indicate that the system sprintf is doing something different. The worst cases appear to be with very small exponents. For example:

Results don't match, format string: %.16e
         sprintf(3): [1.6784992078596053e-265] (23)
        snprintf(3): [1.6784992078596017e-265] (23)
Results don't match, format string: %.16e
         sprintf(3): [1.6784992078596089e-265] (23)
        snprintf(3): [1.6784992078596053e-265] (23)

I am a bit puzzled by the fact that the x86 code is using long double and the microcontroller platform is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant