From 6ee4f51670e983347feb4acb15f681d56117c137 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 11 Nov 2020 11:42:21 +0000 Subject: [PATCH] Add new math procedure: inf_f32 inf_f64 nan_f32 nan_f64 --- core/math/math.odin | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/math/math.odin b/core/math/math.odin index be9da46d3..0a1334e60 100644 --- a/core/math/math.odin +++ b/core/math/math.odin @@ -593,6 +593,30 @@ is_inf :: proc{is_inf_f32, is_inf_f64}; +inf_f32 :: proc(sign: int) -> f32 { + return f32(inf_f64(sign)); +} +inf_f64 :: proc(sign: int) -> f64 { + v: u64; + if sign >= 0 { + v = 0x7ff00000_00000000; + } else { + v = 0xfff00000_00000000; + } + return transmute(f64)v; +} + + +nan_f32 :: proc() -> f32 { + return f32(nan_f64()); +} +nan_f64 :: proc() -> f64 { + v: u64 = 0x7ff80000_00000001; + return transmute(f64)v; +} + + + is_power_of_two :: proc(x: int) -> bool { return x > 0 && (x & (x-1)) == 0; }