diff options
| author | frmdstryr <frmdstryr@protonmail.com> | 2022-05-19 15:04:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-19 15:04:40 -0400 |
| commit | 7b63f98cd7d86337e8157afc9600e1e17c27db80 (patch) | |
| tree | 6f45405e357eecf80f9d7e939ab858d4f11c30b5 /lib/std/math.zig | |
| parent | 50a5ddecc54b88cf295fb97b47fecd2a29a1bf8e (diff) | |
| download | zig-7b63f98cd7d86337e8157afc9600e1e17c27db80.tar.gz zig-7b63f98cd7d86337e8157afc9600e1e17c27db80.zip | |
Add aliases to math builtins back into std.math (#11666)
Diffstat (limited to 'lib/std/math.zig')
| -rw-r--r-- | lib/std/math.zig | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig index 97868a4f7e..b936183482 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -270,6 +270,41 @@ pub const sinh = @import("math/sinh.zig").sinh; pub const cosh = @import("math/cosh.zig").cosh; pub const tanh = @import("math/tanh.zig").tanh; +/// Sine trigonometric function on a floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @sin +pub inline fn sin(value: anytype) @TypeOf(value) { + return @sin(value); +} + +/// Cosine trigonometric function on a floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @cos +pub inline fn cos(value: anytype) @TypeOf(value) { + return @cos(value); +} + +/// Tangent trigonometric function on a floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @tan +pub inline fn tan(value: anytype) @TypeOf(value) { + return @tan(value); +} + +/// Base-e exponential function on a floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @exp +pub inline fn exp(value: anytype) @TypeOf(value) { + return @exp(value); +} + +/// Base-2 exponential function on a floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @exp2 +pub inline fn exp2(value: anytype) @TypeOf(value) { + return @exp2(value); +} + pub const complex = @import("math/complex.zig"); pub const Complex = complex.Complex; @@ -887,6 +922,13 @@ fn testRem() !void { try testing.expectError(error.DivisionByZero, rem(f32, 10, 0)); } +/// Returns the absolute value of a floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @fabs +pub inline fn fabs(value: anytype) @TypeOf(value) { + return @fabs(value); +} + /// Returns the absolute value of the integer parameter. /// Result is an unsigned integer. pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { @@ -987,6 +1029,27 @@ pub fn isPowerOfTwo(v: anytype) bool { return (v & (v - 1)) == 0; } +/// Rounds the given floating point number to an integer, away from zero. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @round +pub inline fn round(value: anytype) @TypeOf(value) { + return @round(value); +} + +/// Rounds the given floating point number to an integer, towards zero. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @trunc +pub inline fn trunc(value: anytype) @TypeOf(value) { + return @trunc(value); +} + +/// Returns the largest integral value not greater than the given floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @floor +pub inline fn floor(value: anytype) @TypeOf(value) { + return @floor(value); +} + /// Returns the nearest power of two less than or equal to value, or /// zero if value is less than or equal to zero. pub fn floorPowerOfTwo(comptime T: type, value: T) T { @@ -1015,6 +1078,13 @@ fn testFloorPowerOfTwo() !void { try testing.expect(floorPowerOfTwo(i4, 0) == 0); } +/// Returns the smallest integral value not less than the given floating point number. +/// Uses a dedicated hardware instruction when available. +/// This is the same as calling the builtin @ceil +pub inline fn ceil(value: anytype) @TypeOf(value) { + return @ceil(value); +} + /// Returns the next power of two (if the value is not already a power of two). /// Only unsigned integers can be used. Zero is not an allowed input. /// Result is a type with 1 more bit than the input type. |
