| ... | @@ -270,6 +270,41 @@ pub const sinh = @import("math/sinh.zig").sinh; | ... | @@ -270,6 +270,41 @@ pub const sinh = @import("math/sinh.zig").sinh; |
| 270 | pub const cosh = @import("math/cosh.zig").cosh; | 270 | pub const cosh = @import("math/cosh.zig").cosh; |
| 271 | pub const tanh = @import("math/tanh.zig").tanh; | 271 | pub const tanh = @import("math/tanh.zig").tanh; |
| 272 | | 272 | |
| | 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 |
| | 276 | pub 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 |
| | 283 | pub 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 |
| | 290 | pub 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 |
| | 297 | pub 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 |
| | 304 | pub inline fn exp2(value: anytype) @TypeOf(value) { |
| | 305 | return @exp2(value); |
| | 306 | } |
| | 307 | |
| 273 | pub const complex = @import("math/complex.zig"); | 308 | pub const complex = @import("math/complex.zig"); |
| 274 | pub const Complex = complex.Complex; | 309 | pub const Complex = complex.Complex; |
| 275 | | 310 | |
| ... | @@ -887,6 +922,13 @@ fn testRem() !void { | ... | @@ -887,6 +922,13 @@ fn testRem() !void { |
| 887 | try testing.expectError(error.DivisionByZero, rem(f32, 10, 0)); | 922 | try testing.expectError(error.DivisionByZero, rem(f32, 10, 0)); |
| 888 | } | 923 | } |
| 889 | | 924 | |
| | 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 |
| | 928 | pub inline fn fabs(value: anytype) @TypeOf(value) { |
| | 929 | return @fabs(value); |
| | 930 | } |
| | 931 | |
| 890 | /// Returns the absolute value of the integer parameter. | 932 | /// Returns the absolute value of the integer parameter. |
| 891 | /// Result is an unsigned integer. | 933 | /// Result is an unsigned integer. |
| 892 | pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { | 934 | pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { |
| ... | @@ -987,6 +1029,27 @@ pub fn isPowerOfTwo(v: anytype) bool { | ... | @@ -987,6 +1029,27 @@ pub fn isPowerOfTwo(v: anytype) bool { |
| 987 | return (v & (v - 1)) == 0; | 1029 | return (v & (v - 1)) == 0; |
| 988 | } | 1030 | } |
| 989 | | 1031 | |
| | 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 |
| | 1035 | pub 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 |
| | 1042 | pub 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 |
| | 1049 | pub inline fn floor(value: anytype) @TypeOf(value) { |
| | 1050 | return @floor(value); |
| | 1051 | } |
| | 1052 | |
| 990 | /// Returns the nearest power of two less than or equal to value, or | 1053 | /// Returns the nearest power of two less than or equal to value, or |
| 991 | /// zero if value is less than or equal to zero. | 1054 | /// zero if value is less than or equal to zero. |
| 992 | pub fn floorPowerOfTwo(comptime T: type, value: T) T { | 1055 | pub fn floorPowerOfTwo(comptime T: type, value: T) T { |
| ... | @@ -1015,6 +1078,13 @@ fn testFloorPowerOfTwo() !void { | ... | @@ -1015,6 +1078,13 @@ fn testFloorPowerOfTwo() !void { |
| 1015 | try testing.expect(floorPowerOfTwo(i4, 0) == 0); | 1078 | try testing.expect(floorPowerOfTwo(i4, 0) == 0); |
| 1016 | } | 1079 | } |
| 1017 | | 1080 | |
| | 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 |
| | 1084 | pub inline fn ceil(value: anytype) @TypeOf(value) { |
| | 1085 | return @ceil(value); |
| | 1086 | } |
| | 1087 | |
| 1018 | /// Returns the next power of two (if the value is not already a power of two). | 1088 | /// Returns the next power of two (if the value is not already a power of two). |
| 1019 | /// Only unsigned integers can be used. Zero is not an allowed input. | 1089 | /// Only unsigned integers can be used. Zero is not an allowed input. |
| 1020 | /// Result is a type with 1 more bit than the input type. | 1090 | /// Result is a type with 1 more bit than the input type. |