From ed36dbbd9c9dc21b2eebae1b31586fea1c6b51c3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 25 Sep 2019 23:35:41 -0400 Subject: mv std/ lib/ that's all this commit does. further commits will fix cli flags and such. see #2221 --- lib/std/math/nan.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/std/math/nan.zig (limited to 'lib/std/math/nan.zig') diff --git a/lib/std/math/nan.zig b/lib/std/math/nan.zig new file mode 100644 index 0000000000..5a01a5b3bd --- /dev/null +++ b/lib/std/math/nan.zig @@ -0,0 +1,24 @@ +const math = @import("../math.zig"); + +/// Returns the nan representation for type T. +pub fn nan(comptime T: type) T { + return switch (T) { + f16 => math.nan_f16, + f32 => math.nan_f32, + f64 => math.nan_f64, + f128 => math.nan_f128, + else => @compileError("nan not implemented for " ++ @typeName(T)), + }; +} + +/// Returns the signalling nan representation for type T. +pub fn snan(comptime T: type) T { + // Note: A signalling nan is identical to a standard right now by may have a different bit + // representation in the future when required. + return switch (T) { + f16 => @bitCast(f16, math.nan_u16), + f32 => @bitCast(f32, math.nan_u32), + f64 => @bitCast(f64, math.nan_u64), + else => @compileError("snan not implemented for " ++ @typeName(T)), + }; +} -- cgit v1.2.3