Skip to content

Commit eb7e6c7

Browse files
committed
Fix float epsilon
1 parent 6ce09cd commit eb7e6c7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/iwasm/aot/aot_intrinsic.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
#include "aot_intrinsic.h"
77

8-
#include <float.h>
9-
108
typedef struct {
119
const char *llvm_intrinsic;
1210
const char *native_intrinsic;
@@ -423,12 +421,14 @@ aot_intrinsic_f64_to_f32(float64 f)
423421
return (float32)f;
424422
}
425423

424+
/* The epsilon value is from https://www.cplusplus.com/reference/cfloat/ */
425+
426426
int32
427427
aot_intrinsic_f32_cmp(AOTFloatCond cond, float32 lhs, float32 rhs)
428428
{
429429
switch (cond) {
430430
case FLOAT_EQ:
431-
return fabsf(lhs - rhs) <= __FLT_EPSILON__ ? 1 : 0;
431+
return fabsf(lhs - rhs) <= 1e-5f ? 1 : 0;
432432

433433
case FLOAT_LT:
434434
return lhs < rhs ? 1 : 0;
@@ -459,7 +459,7 @@ aot_intrinsic_f64_cmp(AOTFloatCond cond, float64 lhs, float64 rhs)
459459
{
460460
switch (cond) {
461461
case FLOAT_EQ:
462-
return fabs(lhs - rhs) <= __DBL_EPSILON__ ? 1 : 0;
462+
return fabs(lhs - rhs) <= 1e-9 ? 1 : 0;
463463

464464
case FLOAT_LT:
465465
return lhs < rhs ? 1 : 0;

0 commit comments

Comments
 (0)