authorgravatar for frmdstryr@protonmail.comfrmdstryr <frmdstryr@protonmail.com> 2022-05-19 15:04:40-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-05-19 15:04:40-04:00
log7b63f98cd7d86337e8157afc9600e1e17c27db80
tree6f45405e357eecf80f9d7e939ab858d4f11c30b5
parent50a5ddecc54b88cf295fb97b47fecd2a29a1bf8e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Add aliases to math builtins back into std.math (#11666)


1 files changed, 70 insertions(+), 0 deletions(-)

lib/std/math.zig+70
......@@ -270,6 +270,41 @@ pub const sinh = @import("math/sinh.zig").sinh;
270270pub const cosh = @import("math/cosh.zig").cosh;
271271pub const tanh = @import("math/tanh.zig").tanh;
272272
273/// Sine trigonometric function on a floating point number.
274/// Uses a dedicated hardware instruction when available.
275/// This is the same as calling the builtin @sin
276pub inline fn sin(value: anytype) @TypeOf(value) {
277 return @sin(value);
278}
279
280/// Cosine trigonometric function on a floating point number.
281/// Uses a dedicated hardware instruction when available.
282/// This is the same as calling the builtin @cos
283pub inline fn cos(value: anytype) @TypeOf(value) {
284 return @cos(value);
285}
286
287/// Tangent trigonometric function on a floating point number.
288/// Uses a dedicated hardware instruction when available.
289/// This is the same as calling the builtin @tan
290pub inline fn tan(value: anytype) @TypeOf(value) {
291 return @tan(value);
292}
293
294/// Base-e exponential function on a floating point number.
295/// Uses a dedicated hardware instruction when available.
296/// This is the same as calling the builtin @exp
297pub inline fn exp(value: anytype) @TypeOf(value) {
298 return @exp(value);
299}
300
301/// Base-2 exponential function on a floating point number.
302/// Uses a dedicated hardware instruction when available.
303/// This is the same as calling the builtin @exp2
304pub inline fn exp2(value: anytype) @TypeOf(value) {
305 return @exp2(value);
306}
307
273308pub const complex = @import("math/complex.zig");
274309pub const Complex = complex.Complex;
275310
......@@ -887,6 +922,13 @@ fn testRem() !void {
887922 try testing.expectError(error.DivisionByZero, rem(f32, 10, 0));
888923}
889924
925/// Returns the absolute value of a floating point number.
926/// Uses a dedicated hardware instruction when available.
927/// This is the same as calling the builtin @fabs
928pub inline fn fabs(value: anytype) @TypeOf(value) {
929 return @fabs(value);
930}
931
890932/// Returns the absolute value of the integer parameter.
891933/// Result is an unsigned integer.
892934pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) {
......@@ -987,6 +1029,27 @@ pub fn isPowerOfTwo(v: anytype) bool {
9871029 return (v & (v - 1)) == 0;
9881030}
9891031
1032/// Rounds the given floating point number to an integer, away from zero.
1033/// Uses a dedicated hardware instruction when available.
1034/// This is the same as calling the builtin @round
1035pub inline fn round(value: anytype) @TypeOf(value) {
1036 return @round(value);
1037}
1038
1039/// Rounds the given floating point number to an integer, towards zero.
1040/// Uses a dedicated hardware instruction when available.
1041/// This is the same as calling the builtin @trunc
1042pub inline fn trunc(value: anytype) @TypeOf(value) {
1043 return @trunc(value);
1044}
1045
1046/// Returns the largest integral value not greater than the given floating point number.
1047/// Uses a dedicated hardware instruction when available.
1048/// This is the same as calling the builtin @floor
1049pub inline fn floor(value: anytype) @TypeOf(value) {
1050 return @floor(value);
1051}
1052
9901053/// Returns the nearest power of two less than or equal to value, or
9911054/// zero if value is less than or equal to zero.
9921055pub fn floorPowerOfTwo(comptime T: type, value: T) T {
......@@ -1015,6 +1078,13 @@ fn testFloorPowerOfTwo() !void {
10151078 try testing.expect(floorPowerOfTwo(i4, 0) == 0);
10161079}
10171080
1081/// Returns the smallest integral value not less than the given floating point number.
1082/// Uses a dedicated hardware instruction when available.
1083/// This is the same as calling the builtin @ceil
1084pub inline fn ceil(value: anytype) @TypeOf(value) {
1085 return @ceil(value);
1086}
1087
10181088/// Returns the next power of two (if the value is not already a power of two).
10191089/// Only unsigned integers can be used. Zero is not an allowed input.
10201090/// Result is a type with 1 more bit than the input type.