@@ -4,14 +4,14 @@ const expect = std.testing.expect;
44
55/// Returns whether x is a finite value.
66pub fn isFinite (x : anytype ) bool {
7- const T = @TypeOf (x );
7+ const T = if ( @TypeOf ( x ) == comptime_float ) f128 else @TypeOf (x );
88 const TBits = std .meta .Int (.unsigned , @typeInfo (T ).float .bits );
99 const remove_sign = ~ @as (TBits , 0 ) >> 1 ;
10- return @as (TBits , @bitCast (x )) & remove_sign < @as (TBits , @bitCast (math .inf (T )));
10+ return @as (TBits , @bitCast (@as ( T , x ) )) & remove_sign < @as (TBits , @bitCast (math .inf (T )));
1111}
1212
1313test isFinite {
14- inline for ([_ ]type { f16 , f32 , f64 , f80 , f128 }) | T | {
14+ inline for ([_ ]type { f16 , f32 , f64 , f80 , f128 , comptime_float }) | T | {
1515 // normals
1616 try expect (isFinite (@as (T , 1.0 )));
1717 try expect (isFinite (- @as (T , 1.0 )));
@@ -25,6 +25,8 @@ test isFinite {
2525 try expect (isFinite (math .floatMin (T )));
2626 try expect (isFinite (math .floatMax (T )));
2727
28+ if (T == comptime_float ) return ;
29+
2830 // inf & nan
2931 try expect (! isFinite (math .inf (T )));
3032 try expect (! isFinite (- math .inf (T )));
0 commit comments