@@ -54,18 +54,24 @@ inline fn generic_fmin(comptime T: type, x: T, y: T) T {
54
54
return y ;
55
55
if (math .isNan (y ))
56
56
return x ;
57
+ if (math .signbit (x ) != math .signbit (y ))
58
+ return if (math .signbit (x )) x else y ;
57
59
return if (x < y ) x else y ;
58
60
}
59
61
60
62
test "generic_fmin" {
61
63
inline for ([_ ]type { f32 , f64 , c_longdouble , f80 , f128 }) | T | {
62
64
const nan_val = math .nan (T );
65
+ const Int = std .meta .Int (.unsigned , @bitSizeOf (T ));
63
66
64
67
try std .testing .expect (math .isNan (generic_fmin (T , nan_val , nan_val )));
65
68
try std .testing .expectEqual (@as (T , 1.0 ), generic_fmin (T , nan_val , 1.0 ));
66
69
try std .testing .expectEqual (@as (T , 1.0 ), generic_fmin (T , 1.0 , nan_val ));
67
70
68
71
try std .testing .expectEqual (@as (T , 1.0 ), generic_fmin (T , 1.0 , 10.0 ));
69
72
try std .testing .expectEqual (@as (T , -1.0 ), generic_fmin (T , 1.0 , -1.0 ));
73
+
74
+ try std .testing .expectEqual (@as (Int , @bitCast (@as (T , -0.0 ))), @as (Int , @bitCast (generic_fmin (T , 0.0 , -0.0 ))));
75
+ try std .testing .expectEqual (@as (Int , @bitCast (@as (T , -0.0 ))), @as (Int , @bitCast (generic_fmin (T , -0.0 , 0.0 ))));
70
76
}
71
77
}
0 commit comments