Skip to content

Commit 30e2967

Browse files
committed
Move float epsilon to bh_platform
1 parent eb7e6c7 commit 30e2967

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

core/iwasm/aot/aot_intrinsic.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,12 @@ aot_intrinsic_f64_to_f32(float64 f)
421421
return (float32)f;
422422
}
423423

424-
/* The epsilon value is from https://www.cplusplus.com/reference/cfloat/ */
425-
426424
int32
427425
aot_intrinsic_f32_cmp(AOTFloatCond cond, float32 lhs, float32 rhs)
428426
{
429427
switch (cond) {
430428
case FLOAT_EQ:
431-
return fabsf(lhs - rhs) <= 1e-5f ? 1 : 0;
429+
return (float32)fabs(lhs - rhs) <= WA_FLT_EPSILON ? 1 : 0;
432430

433431
case FLOAT_LT:
434432
return lhs < rhs ? 1 : 0;
@@ -459,7 +457,7 @@ aot_intrinsic_f64_cmp(AOTFloatCond cond, float64 lhs, float64 rhs)
459457
{
460458
switch (cond) {
461459
case FLOAT_EQ:
462-
return fabs(lhs - rhs) <= 1e-9 ? 1 : 0;
460+
return fabs(lhs - rhs) <= WA_DBL_EPSILON ? 1 : 0;
463461

464462
case FLOAT_LT:
465463
return lhs < rhs ? 1 : 0;

core/shared/utils/bh_platform.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@
3535
#define WA_FREE wasm_runtime_free
3636
#endif
3737

38+
/* The epsilon value is from https://www.cplusplus.com/reference/cfloat/ */
39+
40+
#define WA_FLT_EPSILON 1e-5f
41+
#define WA_DBL_EPSILON 1e-9
42+
3843
#endif /* #ifndef _BH_PLATFORM_H */

0 commit comments

Comments
 (0)