Skip to content

Commit a3186c1

Browse files
committed
print warning for extremely small REALs
they may be misinterpreted on some platforms or with some EXPRESS parsers
1 parent 6312ac5 commit a3186c1

File tree

5 files changed

+492
-472
lines changed

5 files changed

+492
-472
lines changed

include/express/express.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extern SC_EXPRESS_EXPORT Error ERROR_unlabelled_param_type;
109109
extern SC_EXPRESS_EXPORT Error ERROR_file_unreadable;
110110
extern SC_EXPRESS_EXPORT Error ERROR_file_unwriteable;
111111
extern SC_EXPRESS_EXPORT Error ERROR_warn_unsupported_lang_feat;
112+
extern SC_EXPRESS_EXPORT Error ERROR_warn_small_real;
112113

113114
extern SC_EXPRESS_EXPORT struct Scope_ * FUNC_NVL;
114115
extern SC_EXPRESS_EXPORT struct Scope_ * FUNC_USEDIN;

src/express/expparse.y

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ YYSTYPE yylval;
9898
#include "express/entity.h"
9999
#include "express/resolve.h"
100100
#include "expscan.h"
101+
#include <float.h>
101102

102103
extern int print_objects_while_running;
103104

@@ -1586,6 +1587,12 @@ literal(A) ::= TOK_INTEGER_LITERAL(B).
15861587
}
15871588
literal(A) ::= TOK_REAL_LITERAL(B).
15881589
{
1590+
if( ( abs( B.rVal ) <= FLT_EPSILON ) && ( abs( B.rVal ) > 0 ) ) {
1591+
Symbol sym;
1592+
sym.line = yylineno;
1593+
sym.filename = current_filename;
1594+
ERRORreport_with_symbol(ERROR_warn_small_real, &sym, B.rVal );
1595+
}
15891596
if( abs( B.rVal ) < DBL_EPSILON ) {
15901597
A = LITERAL_ZERO;
15911598
} else {

src/express/express.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Error ERROR_unlabelled_param_type = ERROR_none;
112112
Error ERROR_file_unreadable;
113113
Error ERROR_file_unwriteable;
114114
Error ERROR_warn_unsupported_lang_feat;
115+
Error ERROR_warn_small_real;
115116

116117
struct Scope_ * FUNC_NVL;
117118
struct Scope_ * FUNC_USEDIN;
@@ -522,11 +523,14 @@ void EXPRESSinitialize( void ) {
522523
ERROR_file_unreadable = ERRORcreate( "Could not read file %s: %s", SEVERITY_ERROR );
523524
ERROR_file_unwriteable = ERRORcreate( "Could not write file %s: %s", SEVERITY_ERROR );
524525
ERROR_warn_unsupported_lang_feat = ERRORcreate( "Unsupported language feature (%s) at %s:%d", SEVERITY_WARNING );
526+
ERROR_warn_small_real = ERRORcreate( "REAL with extremely small magnitude may be interpreted as zero on some "
527+
"platforms or by other parsers - abs(%f) <= FLT_EPSILON", SEVERITY_WARNING );
525528

526529
OBJcreate( OBJ_EXPRESS, EXPRESS_get_symbol, "express file", OBJ_UNUSED_BITS );
527530

528531
ERRORcreate_warning( "unknown_subtype", ERROR_unknown_subtype );
529532
ERRORcreate_warning( "unsupported", ERROR_warn_unsupported_lang_feat );
533+
ERRORcreate_warning( "limits", ERROR_warn_small_real );
530534

531535
EXPRESS_PATHinit(); /* note, must follow defn of errors it needs! */
532536
}
@@ -544,6 +548,7 @@ void EXPRESScleanup( void ) {
544548
ERRORdestroy( ERROR_file_unreadable );
545549
ERRORdestroy( ERROR_file_unwriteable );
546550
ERRORdestroy( ERROR_warn_unsupported_lang_feat );
551+
ERRORdestroy( ERROR_warn_small_real );
547552

548553
DICTcleanup();
549554
OBJcleanup();

0 commit comments

Comments
 (0)