@@ -113,17 +113,7 @@ static prjm_eval_function_def_t intrinsic_function_table[] = {
113113 assert(ctx->func)
114114
115115/* Allowed error for float/double comparisons to exact values */
116- #define COMPARE_CLOSEFACTOR 0.00001
117- static const PRJM_EVAL_F close_factor = COMPARE_CLOSEFACTOR ;
118-
119- /* These factors are not exactly as close to zero as their ns-eel2 equivalents, but that shouldn't
120- * matter too much. In ns-eel2, the value is represented as binary 0x00000000FFFFFFFF for doubles.
121- */
122- #if PRJM_F_SIZE == 4
123- static const PRJM_EVAL_F close_factor_low = 1e-41 ;
124- #else
125- static const PRJM_EVAL_F close_factor_low = 1e-300 ;
126- #endif
116+ #define COMPARE_CLOSEFACTOR ((PRJM_EVAL_F)0.00001)
127117
128118/* Maximum number of loop iterations */
129119#define MAX_LOOP_COUNT 1048576
@@ -297,7 +287,7 @@ prjm_eval_function_decl(execute_while)
297287 do
298288 {
299289 invoke_arg (0 , & value_ptr );
300- } while (fabs (* value_ptr ) > close_factor_low && -- loop_count_int );
290+ } while (fabs (* value_ptr ) > COMPARE_CLOSEFACTOR && -- loop_count_int );
301291
302292 assign_ret_ref (value_ptr );
303293}
@@ -436,7 +426,7 @@ prjm_eval_function_decl(bnot)
436426
437427 invoke_arg (0 , & value_ptr );
438428
439- assign_ret_val (fabs (* value_ptr ) < close_factor_low ? 1.0 : 0.0 );
429+ assign_ret_val (fabs (* value_ptr ) < COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
440430}
441431
442432prjm_eval_function_decl (equal )
@@ -451,7 +441,7 @@ prjm_eval_function_decl(equal)
451441 invoke_arg (0 , & val1_ptr );
452442 invoke_arg (1 , & val2_ptr );
453443
454- assign_ret_val (fabs (* val1_ptr - * val2_ptr ) < close_factor_low ? 1.0 : 0.0 );
444+ assign_ret_val (fabs (* val1_ptr - * val2_ptr ) < COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
455445}
456446
457447prjm_eval_function_decl (notequal )
@@ -465,7 +455,7 @@ prjm_eval_function_decl(notequal)
465455 invoke_arg (0 , & val1_ptr );
466456 invoke_arg (1 , & val2_ptr );
467457
468- assign_ret_val (fabs (* val1_ptr - * val2_ptr ) > close_factor_low ? 1.0 : 0.0 );
458+ assign_ret_val (fabs (* val1_ptr - * val2_ptr ) > COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
469459}
470460
471461prjm_eval_function_decl (below )
@@ -585,7 +575,7 @@ prjm_eval_function_decl(div)
585575 invoke_arg (0 , & val1_ptr );
586576 invoke_arg (1 , & val2_ptr );
587577
588- if (fabs (* val2_ptr ) < close_factor_low )
578+ if (fabs (* val2_ptr ) < COMPARE_CLOSEFACTOR )
589579 {
590580 assign_ret_val (0.0 );
591581 return ;
@@ -630,11 +620,11 @@ prjm_eval_function_decl(boolean_and_op)
630620 */
631621 invoke_arg (0 , & val1_ptr );
632622
633- if (fabs (* val1_ptr ) > close_factor_low )
623+ if (fabs (* val1_ptr ) > COMPARE_CLOSEFACTOR )
634624 {
635625 invoke_arg (1 , & val2_ptr );
636626
637- assign_ret_val (fabs (* val2_ptr ) > close_factor_low ? 1.0 : 0.0 );
627+ assign_ret_val (fabs (* val2_ptr ) > COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
638628 }
639629 else
640630 {
@@ -657,11 +647,11 @@ prjm_eval_function_decl(boolean_or_op)
657647 */
658648 invoke_arg (0 , & val1_ptr );
659649
660- if (fabs (* val1_ptr ) < close_factor_low )
650+ if (fabs (* val1_ptr ) < COMPARE_CLOSEFACTOR )
661651 {
662652 invoke_arg (1 , & val2_ptr );
663653
664- assign_ret_val (fabs (* val2_ptr ) > close_factor_low ? 1.0 : 0.0 );
654+ assign_ret_val (fabs (* val2_ptr ) > COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
665655 }
666656 else
667657 {
@@ -682,7 +672,7 @@ prjm_eval_function_decl(boolean_and_func)
682672 invoke_arg (1 , & val2_ptr );
683673
684674 /* This function also uses the larger close factor! */
685- assign_ret_val (fabs (* val1_ptr ) > close_factor && fabs (* val2_ptr ) > close_factor ? 1.0 : 0.0 );
675+ assign_ret_val (fabs (* val1_ptr ) > COMPARE_CLOSEFACTOR && fabs (* val2_ptr ) > COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
686676}
687677
688678prjm_eval_function_decl (boolean_or_func )
@@ -698,7 +688,7 @@ prjm_eval_function_decl(boolean_or_func)
698688 invoke_arg (1 , & val2_ptr );
699689
700690 /* This function also uses the larger close factor! */
701- assign_ret_val (fabs (* val1_ptr ) > close_factor || fabs (* val2_ptr ) > close_factor ? 1.0 : 0.0 );
691+ assign_ret_val (fabs (* val1_ptr ) > COMPARE_CLOSEFACTOR || fabs (* val2_ptr ) > COMPARE_CLOSEFACTOR ? 1.0 : 0.0 );
702692}
703693
704694prjm_eval_function_decl (neg )
@@ -762,7 +752,7 @@ prjm_eval_function_decl(div_op)
762752 invoke_arg (0 , ret_val );
763753 invoke_arg (1 , & val2_ptr );
764754
765- if (fabs (* val2_ptr ) < close_factor_low )
755+ if (fabs (* val2_ptr ) < COMPARE_CLOSEFACTOR )
766756 {
767757 assign_ret_val (0.0 );
768758 return ;
@@ -856,7 +846,7 @@ prjm_eval_function_decl(pow_op)
856846 invoke_arg (0 , ret_val );
857847 invoke_arg (1 , & val2_ptr );
858848
859- if (fabs (* * ret_val ) < close_factor_low && * val2_ptr < 0 )
849+ if (fabs (* * ret_val ) < COMPARE_CLOSEFACTOR && * val2_ptr < 0 )
860850 {
861851 assign_ret_val (.0 );
862852 return ;
@@ -992,7 +982,7 @@ prjm_eval_function_decl(pow)
992982 invoke_arg (0 , & math_arg1_ptr );
993983 invoke_arg (1 , & math_arg2_ptr );
994984
995- if (fabs (* math_arg1_ptr ) < close_factor_low && * math_arg2_ptr < 0 )
985+ if (fabs (* math_arg1_ptr ) < COMPARE_CLOSEFACTOR && * math_arg2_ptr < 0 )
996986 {
997987 assign_ret_val (.0 );
998988 return ;
@@ -1088,7 +1078,7 @@ prjm_eval_function_decl(sigmoid)
10881078 invoke_arg (1 , & math_arg2_ptr );
10891079
10901080 double t = (1 + exp ((double ) - (* math_arg1_ptr ) * (* math_arg2_ptr )));
1091- assign_ret_val ((PRJM_EVAL_F ) (fabs (t ) > close_factor ? 1.0 / t : .0 ));
1081+ assign_ret_val ((PRJM_EVAL_F ) (fabs (t ) > COMPARE_CLOSEFACTOR ? 1.0 / t : .0 ));
10921082}
10931083
10941084prjm_eval_function_decl (sqr )
0 commit comments