Mathematical (exp) function result vs glibc version

249 views Asked by At

I need your help regarding an explanation (and maybe a workaround) regarding different results produced by exp() mathematical function on some Linux distros.

Results are produced by this very simple program :

#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>

int main() {
  double a = -9.55258983280695383e-03;
  std::cout << std::setprecision(std::numeric_limits< double >::max_digits10) << std::scientific ;
  std::cout << exp(a) << ";" <<  expf(a) << ";" << expl(a) << std::endl;
}

As you can see, double, float and long double version of exp() function are tested.

$ g++ -std=c++11 exp.cxx
$ ./a.out

Results by distros :

exp(a) expf(a) expl(a)
stretch 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
buster 9.90492891217632510e-01 9.90492880344390869e-01 9.90492891217632453e-01
bullseye 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
bookworm 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
xenial 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
focal 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
jammy 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
Maipo 9.90492891217632399e-01 9.90492880344390869e-01 9.90492891217632453e-01
Ootpa 9.90492891217632510e-01 9.90492880344390869e-01 9.90492891217632453e-01

Why do buster (debian 10) and Ootpa (RedHat 8) return (the same) different value ?

Where to search for an explanation ?

I noticed that glibc versions are the same (2.28) for buster and Ootpa and that any other version returns the expected result :

g++ glibc
stretch 6.3.0 2.24
buster 8.3.0 2.28
bullseye 10.2.1 2.31
bookworm 11.3.0 2.33
xenial 5.4.0 2.23
focal 9.4.0 2.31
jammy 11.2.0 2.35
Maipo 4.8.5 2.17
Ootpa 8.5.0 2.28

Any suggestion ?

0

There are 0 answers