mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Add aliases to math builtins back into std.math (#11666)
This commit is contained in:
parent
50a5ddecc5
commit
7b63f98cd7
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user