Skip to content

Commit

Permalink
math: avoid runtime conversions of floating-point constants
Browse files Browse the repository at this point in the history
gcc-12 with -frounding-mode will do inexact constant conversions at
runtime according to the runtime rounding mode.

in the math library we want constants to be rounding mode independent
so this patch fixes cases where new runtime conversions happen with
gcc-12.

fortunately this only affects two minor cases, the fix uses global
initializers where rounding mode does not apply.

after the patch the same amount of conversions happen with gcc-12 as
with gcc-11.
  • Loading branch information
Szabolcs Nagy authored and richfelker committed Mar 8, 2022
1 parent f8bdc30 commit 7c0c7a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/complex/cacosf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

// FIXME

static const float float_pi_2 = M_PI_2;

float complex cacosf(float complex z)
{
z = casinf(z);
return CMPLXF((float)M_PI_2 - crealf(z), -cimagf(z));
return CMPLXF(float_pi_2 - crealf(z), -cimagf(z));
}
4 changes: 3 additions & 1 deletion src/complex/catanf.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ static const double DP1 = 3.140625;
static const double DP2 = 9.67502593994140625E-4;
static const double DP3 = 1.509957990978376432E-7;

static const float float_pi = M_PI;

static float _redupif(float xx)
{
float x, t;
long i;

x = xx;
t = x/(float)M_PI;
t = x/float_pi;
if (t >= 0.0f)
t += 0.5f;
else
Expand Down

0 comments on commit 7c0c7a7

Please sign in to comment.