diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-04-26 10:13:55 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-04-27 12:20:44 -0700 |
| commit | 41dd2beaacade94c5c98400a4a655aea07b9e2f3 (patch) | |
| tree | d7cd75c3ded0e8517e801f62dbb883d93f3cd585 /lib/std/math.zig | |
| parent | 6f4343b61afe36a709e713735947561a2b76bce8 (diff) | |
| download | zig-41dd2beaacade94c5c98400a4a655aea07b9e2f3.tar.gz zig-41dd2beaacade94c5c98400a4a655aea07b9e2f3.zip | |
compiler-rt: math functions reorg
* unify the logic for exporting math functions from compiler-rt,
with the appropriate suffixes and prefixes.
- add all missing f128 and f80 exports. Functions with missing
implementations call other functions and have TODO comments.
- also add f16 functions
* move math functions from freestanding libc to compiler-rt (#7265)
* enable all the f128 and f80 code in the stage2 compiler and behavior
tests (#11161).
* update std lib to use builtins rather than `std.math`.
Diffstat (limited to 'lib/std/math.zig')
| -rw-r--r-- | lib/std/math.zig | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig index b229c8973e..214ade39ce 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -138,7 +138,7 @@ pub fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool { if (isNan(x) or isNan(y)) return false; - return fabs(x - y) <= tolerance; + return @fabs(x - y) <= tolerance; } /// Performs an approximate comparison of two floating point values `x` and `y`. @@ -166,7 +166,7 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool { if (isNan(x) or isNan(y)) return false; - return fabs(x - y) <= max(fabs(x), fabs(y)) * tolerance; + return @fabs(x - y) <= max(@fabs(x), @fabs(y)) * tolerance; } pub fn approxEq(comptime T: type, x: T, y: T, tolerance: T) bool { @@ -233,11 +233,6 @@ pub fn raiseDivByZero() void { pub const isNan = @import("math/isnan.zig").isNan; pub const isSignalNan = @import("math/isnan.zig").isSignalNan; -pub const fabs = @import("math/fabs.zig").fabs; -pub const ceil = @import("math/ceil.zig").ceil; -pub const floor = @import("math/floor.zig").floor; -pub const trunc = @import("math/trunc.zig").trunc; -pub const round = @import("math/round.zig").round; pub const frexp = @import("math/frexp.zig").frexp; pub const Frexp = @import("math/frexp.zig").Frexp; pub const modf = @import("math/modf.zig").modf; @@ -261,8 +256,6 @@ pub const asin = @import("math/asin.zig").asin; pub const atan = @import("math/atan.zig").atan; pub const atan2 = @import("math/atan2.zig").atan2; pub const hypot = @import("math/hypot.zig").hypot; -pub const exp = @import("math/exp.zig").exp; -pub const exp2 = @import("math/exp2.zig").exp2; pub const expm1 = @import("math/expm1.zig").expm1; pub const ilogb = @import("math/ilogb.zig").ilogb; pub const ln = @import("math/ln.zig").ln; @@ -270,16 +263,12 @@ pub const log = @import("math/log.zig").log; pub const log2 = @import("math/log2.zig").log2; pub const log10 = @import("math/log10.zig").log10; pub const log1p = @import("math/log1p.zig").log1p; -pub const fma = @import("math/fma.zig").fma; pub const asinh = @import("math/asinh.zig").asinh; pub const acosh = @import("math/acosh.zig").acosh; pub const atanh = @import("math/atanh.zig").atanh; pub const sinh = @import("math/sinh.zig").sinh; pub const cosh = @import("math/cosh.zig").cosh; pub const tanh = @import("math/tanh.zig").tanh; -pub const cos = @import("math/cos.zig").cos; -pub const sin = @import("math/sin.zig").sin; -pub const tan = @import("math/tan.zig").tan; pub const complex = @import("math/complex.zig"); pub const Complex = complex.Complex; @@ -716,17 +705,6 @@ fn testAbsInt() !void { try testing.expect((absInt(@as(i32, 10)) catch unreachable) == 10); } -pub const absFloat = fabs; - -test "absFloat" { - try testAbsFloat(); - comptime try testAbsFloat(); -} -fn testAbsFloat() !void { - try testing.expect(absFloat(@as(f32, -10.05)) == 10.05); - try testing.expect(absFloat(@as(f32, 10.05)) == 10.05); -} - /// Divide numerator by denominator, rounding toward zero. Returns an /// error on overflow or when denominator is zero. pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T { @@ -1400,11 +1378,6 @@ test "order.compare" { try testing.expect(order(1, 0).compare(.neq)); } -test "comptime sin and ln" { - const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5))); - try testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); -} - /// Returns a mask of all ones if value is true, /// and a mask of all zeroes if value is false. /// Compiles to one instruction for register sized integers. |
