about summary refs log tree commit diff
path: root/src/complex/cacosf.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2022-02-04 21:04:45 +0100
committerRich Felker <dalias@aerifal.cx>2022-03-08 16:27:15 -0500
commit7c0c7a75ec8ecf3eedefc40bb4dae5aaa76d7108 (patch)
treec787eb03223648195b3b96174cdadc1e0556f382 /src/complex/cacosf.c
parentf8bdc3048216f41eaaf655524fa286cfb1184a70 (diff)
downloadmusl-7c0c7a75ec8ecf3eedefc40bb4dae5aaa76d7108.tar.gz
musl-7c0c7a75ec8ecf3eedefc40bb4dae5aaa76d7108.tar.xz
musl-7c0c7a75ec8ecf3eedefc40bb4dae5aaa76d7108.zip
math: avoid runtime conversions of floating-point constants
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.
Diffstat (limited to 'src/complex/cacosf.c')
-rw-r--r--src/complex/cacosf.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/complex/cacosf.c b/src/complex/cacosf.c
index 2e048540..ed8acf0f 100644
--- a/src/complex/cacosf.c
+++ b/src/complex/cacosf.c
@@ -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));
 }