authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-22 10:47:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-22 10:48:45-07:00
log86b92809635607ff357ce96902e2aaf83c3fd029
tree5179c5f046618c054b2778cbb97a945e5e07f642
parentd0dceae736edb43d4c217306a2b0445277f184ce

zig libc: export floorl and ceill

needed since self-hosted now contains calls to `@divFloor` and `@divTrunc` for 128-bit floats.

3 files changed, 28 insertions(+), 11 deletions(-)

lib/std/math/ceil.zig+4
...@@ -20,6 +20,10 @@ pub fn ceil(x: anytype) @TypeOf(x) {...@@ -20,6 +20,10 @@ pub fn ceil(x: anytype) @TypeOf(x) {
20 f32 => ceil32(x),20 f32 => ceil32(x),
21 f64 => ceil64(x),21 f64 => ceil64(x),
22 f128 => ceil128(x),22 f128 => ceil128(x),
23
24 // TODO this is not correct for some targets
25 c_longdouble => @floatCast(c_longdouble, ceil128(x)),
26
23 else => @compileError("ceil not implemented for " ++ @typeName(T)),27 else => @compileError("ceil not implemented for " ++ @typeName(T)),
24 };28 };
25}29}
lib/std/math/floor.zig+4
...@@ -21,6 +21,10 @@ pub fn floor(x: anytype) @TypeOf(x) {...@@ -21,6 +21,10 @@ pub fn floor(x: anytype) @TypeOf(x) {
21 f32 => floor32(x),21 f32 => floor32(x),
22 f64 => floor64(x),22 f64 => floor64(x),
23 f128 => floor128(x),23 f128 => floor128(x),
24
25 // TODO this is not correct for some targets
26 c_longdouble => @floatCast(c_longdouble, floor128(x)),
27
24 else => @compileError("floor not implemented for " ++ @typeName(T)),28 else => @compileError("floor not implemented for " ++ @typeName(T)),
25 };29 };
26}30}
lib/std/special/c_stage1.zig+20-11
...@@ -644,32 +644,41 @@ export fn fmod(x: f64, y: f64) f64 {...@@ -644,32 +644,41 @@ export fn fmod(x: f64, y: f64) f64 {
644export fn floorf(x: f32) f32 {644export fn floorf(x: f32) f32 {
645 return math.floor(x);645 return math.floor(x);
646}646}
647
648export fn ceilf(x: f32) f32 {
649 return math.ceil(x);
650}
651
652export fn floor(x: f64) f64 {647export fn floor(x: f64) f64 {
653 return math.floor(x);648 return math.floor(x);
654}649}
650export fn floorl(x: c_longdouble) c_longdouble {
651 if (!long_double_is_f128) {
652 @panic("TODO implement this");
653 }
654 return math.floor(x);
655}
655656
657export fn ceilf(x: f32) f32 {
658 return math.ceil(x);
659}
656export fn ceil(x: f64) f64 {660export fn ceil(x: f64) f64 {
657 return math.ceil(x);661 return math.ceil(x);
658}662}
659663export fn ceill(x: c_longdouble) c_longdouble {
660export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble {
661 if (!long_double_is_f128) {664 if (!long_double_is_f128) {
662 @panic("TODO implement this");665 @panic("TODO implement this");
663 }666 }
664 return math.fma(c_longdouble, a, b, c);667 return math.ceil(x);
668}
669
670export fn fmaf(a: f32, b: f32, c: f32) f32 {
671 return math.fma(f32, a, b, c);
665}672}
666673
667export fn fma(a: f64, b: f64, c: f64) f64 {674export fn fma(a: f64, b: f64, c: f64) f64 {
668 return math.fma(f64, a, b, c);675 return math.fma(f64, a, b, c);
669}676}
670677export fn fmal(a: c_longdouble, b: c_longdouble, c: c_longdouble) c_longdouble {
671export fn fmaf(a: f32, b: f32, c: f32) f32 {678 if (!long_double_is_f128) {
672 return math.fma(f32, a, b, c);679 @panic("TODO implement this");
680 }
681 return math.fma(c_longdouble, a, b, c);
673}682}
674683
675export fn sin(a: f64) f64 {684export fn sin(a: f64) f64 {