From d987bf859e6d8511abb49b258c4d764bd32acc8e Mon Sep 17 00:00:00 2001 From: kkHAIKE Date: Mon, 19 Sep 2022 15:39:56 +0800 Subject: Sema: add float128IntPartToBigInt to fix compare comptime float with int --- src/value.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/value.zig') diff --git a/src/value.zig b/src/value.zig index 01df65a715..7a0636dda0 100644 --- a/src/value.zig +++ b/src/value.zig @@ -1999,6 +1999,11 @@ pub const Value = extern union { } return true; }, + .float_16 => if (std.math.isNan(lhs.castTag(.float_16).?.data)) return op != .neq, + .float_32 => if (std.math.isNan(lhs.castTag(.float_32).?.data)) return op != .neq, + .float_64 => if (std.math.isNan(lhs.castTag(.float_64).?.data)) return op != .neq, + .float_80 => if (std.math.isNan(lhs.castTag(.float_80).?.data)) return op != .neq, + .float_128 => if (std.math.isNan(lhs.castTag(.float_128).?.data)) return op != .neq, else => {}, } return (try orderAgainstZeroAdvanced(lhs, sema_kit)).compare(op); @@ -3596,6 +3601,18 @@ pub const Value = extern union { }; } + /// Returns true if the value is a floating point type and is infinite. Returns false otherwise. + pub fn isInf(val: Value) bool { + return switch (val.tag()) { + .float_16 => std.math.isInf(val.castTag(.float_16).?.data), + .float_32 => std.math.isInf(val.castTag(.float_32).?.data), + .float_64 => std.math.isInf(val.castTag(.float_64).?.data), + .float_80 => std.math.isInf(val.castTag(.float_80).?.data), + .float_128 => std.math.isInf(val.castTag(.float_128).?.data), + else => false, + }; + } + pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value { if (float_type.zigTypeTag() == .Vector) { const result_data = try arena.alloc(Value, float_type.vectorLen()); -- cgit v1.2.3