| author | |
| committer | |
| log | 521a093334eb92b4fd2430b9018ed94b912857a8 |
| tree | 7aa1be7b8c66715c851e74cc93b315c0dfe4e0cb |
| parent | dcffee067290c03f89c5afcacab1ba543ee28e7c |
| signature |
The `frexp` implementation was generalized so it can be used for `f32`
and `c_longdouble` types as well.
The changes were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib
$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=frexp -fqemu -fwasmtime --summary line
Build Summary: 737/737 steps succeeded
$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=frexpf -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```6 files changed, 11 insertions(+), 41 deletions(-)
lib/c/math.zig+11-2| ... | ... | @@ -36,6 +36,7 @@ comptime { |
| 36 | 36 | |
| 37 | 37 | if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 38 | 38 | symbol(&coshf, "coshf"); |
| 39 | symbol(&frexpf, "frexpf"); | |
| 39 | 40 | symbol(&hypotf, "hypotf"); |
| 40 | 41 | symbol(&hypotl, "hypotl"); |
| 41 | 42 | symbol(&modff, "modff"); |
| ... | ... | @@ -162,7 +163,7 @@ fn fdim(x: f64, y: f64) callconv(.c) f64 { |
| 162 | 163 | return 0; |
| 163 | 164 | } |
| 164 | 165 | |
| 165 | fn frexp(x: f64, e: *c_int) callconv(.c) f64 { | |
| 166 | fn frexpGeneric(comptime T: type, x: T, e: *c_int) T { | |
| 166 | 167 | // libc expects `*e` to be unspecified in this case; an unspecified C value |
| 167 | 168 | // should be a valid value of the relevant type, yet Zig's std |
| 168 | 169 | // implementation sets it to `undefined` -- which can even be nonsense |
| ... | ... | @@ -170,7 +171,7 @@ fn frexp(x: f64, e: *c_int) callconv(.c) f64 { |
| 170 | 171 | // int value in Zig -- a zero. |
| 171 | 172 | // |
| 172 | 173 | // This mirrors the handling of infinities, where libc also expects |
| 173 | // unspecified for the value `*e` and Zig std sets it to a zero. | |
| 174 | // unspecified for the value of `*e` and Zig std sets it to a zero. | |
| 174 | 175 | if (math.isNan(x)) { |
| 175 | 176 | e.* = 0; |
| 176 | 177 | return x; |
| ... | ... | @@ -181,6 +182,14 @@ fn frexp(x: f64, e: *c_int) callconv(.c) f64 { |
| 181 | 182 | return r.significand; |
| 182 | 183 | } |
| 183 | 184 | |
| 185 | fn frexp(x: f64, e: *c_int) callconv(.c) f64 { | |
| 186 | return frexpGeneric(f64, x, e); | |
| 187 | } | |
| 188 | ||
| 189 | fn frexpf(x: f32, e: *c_int) callconv(.c) f32 { | |
| 190 | return frexpGeneric(f32, x, e); | |
| 191 | } | |
| 192 | ||
| 184 | 193 | fn hypot(x: f64, y: f64) callconv(.c) f64 { |
| 185 | 194 | return math.hypot(x, y); |
| 186 | 195 | } |
lib/libc/mingw/math/frexpf.c deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | /** | |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. | |
| 3 | * This file is part of the mingw-w64 runtime package. | |
| 4 | * No warranty is given; refer to the file DISCLAIMER.PD within this package. | |
| 5 | */ | |
| 6 | extern double __cdecl frexp(double _X,int *_Y); | |
| 7 | ||
| 8 | float frexpf (float, int *); | |
| 9 | float frexpf (float x, int *expn) | |
| 10 | { | |
| 11 | return (float)frexp(x, expn); | |
| 12 | } | |
| 13 |
lib/libc/musl/src/math/frexpf.c deleted-23| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | #include <math.h> | |
| 2 | #include <stdint.h> | |
| 3 | ||
| 4 | float frexpf(float x, int *e) | |
| 5 | { | |
| 6 | 	union { float f; uint32_t i; } y = { x }; | |
| 7 | 	int ee = y.i>>23 & 0xff; | |
| 8 | ||
| 9 | 	if (!ee) { | |
| 10 | 		if (x) { | |
| 11 | 			x = frexpf(x*0x1p64, e); | |
| 12 | 			*e -= 64; | |
| 13 | 		} else *e = 0; | |
| 14 | 		return x; | |
| 15 | 	} else if (ee == 0xff) { | |
| 16 | 		return x; | |
| 17 | 	} | |
| 18 | ||
| 19 | 	*e = ee - 0x7e; | |
| 20 | 	y.i &= 0x807ffffful; | |
| 21 | 	y.i |= 0x3f000000ul; | |
| 22 | 	return y.f; | |
| 23 | } |
src/libs/mingw.zig-1| ... | ... | @@ -613,7 +613,6 @@ const mingw32_generic_src = [_][]const u8{ |
| 613 | 613 | "math" ++ path.sep_str ++ "fpclassify.c", |
| 614 | 614 | "math" ++ path.sep_str ++ "fpclassifyf.c", |
| 615 | 615 | "math" ++ path.sep_str ++ "fpclassifyl.c", |
| 616 | "math" ++ path.sep_str ++ "frexpf.c", | |
| 617 | 616 | "math" ++ path.sep_str ++ "frexpl.c", |
| 618 | 617 | "math" ++ path.sep_str ++ "ldexpf.c", |
| 619 | 618 | "math" ++ path.sep_str ++ "lgamma.c", |
src/libs/musl.zig-1| ... | ... | @@ -839,7 +839,6 @@ const src_files = [_][]const u8{ |
| 839 | 839 | "musl/src/math/__fpclassify.c", |
| 840 | 840 | "musl/src/math/__fpclassifyf.c", |
| 841 | 841 | "musl/src/math/__fpclassifyl.c", |
| 842 | "musl/src/math/frexpf.c", | |
| 843 | 842 | "musl/src/math/frexpl.c", |
| 844 | 843 | "musl/src/math/i386/acosl.s", |
| 845 | 844 | "musl/src/math/i386/asinf.s", |
src/libs/wasi_libc.zig-1| ... | ... | @@ -701,7 +701,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 701 | 701 | "musl/src/math/finitef.c", |
| 702 | 702 | "musl/src/math/fma.c", |
| 703 | 703 | "musl/src/math/fmaf.c", |
| 704 | "musl/src/math/frexpf.c", | |
| 705 | 704 | "musl/src/math/frexpl.c", |
| 706 | 705 | "musl/src/math/ilogb.c", |
| 707 | 706 | "musl/src/math/ilogbf.c", |