aboutsummaryrefslogtreecommitdiff
path: root/lib/std/special/compiler_rt/negXf2.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/special/compiler_rt/negXf2.zig')
-rw-r--r--lib/std/special/compiler_rt/negXf2.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/std/special/compiler_rt/negXf2.zig b/lib/std/special/compiler_rt/negXf2.zig
new file mode 100644
index 0000000000..b71a503c1d
--- /dev/null
+++ b/lib/std/special/compiler_rt/negXf2.zig
@@ -0,0 +1,21 @@
+const std = @import("std");
+
+pub extern fn __negsf2(a: f32) f32 {
+ return negXf2(f32, a);
+}
+
+pub extern fn __negdf2(a: f64) f64 {
+ return negXf2(f64, a);
+}
+
+fn negXf2(comptime T: type, a: T) T {
+ const Z = @IntType(false, T.bit_count);
+
+ const typeWidth = T.bit_count;
+ const significandBits = std.math.floatMantissaBits(T);
+ const exponentBits = std.math.floatExponentBits(T);
+
+ const signBit = (Z(1) << (significandBits + exponentBits));
+
+ return @bitCast(T, @bitCast(Z, a) ^ signBit);
+}