From cf2b871879db537baba19bf64e6b308671d56f3b Mon Sep 17 00:00:00 2001 From: rms Date: Wed, 31 Mar 1993 05:44:03 +0000 Subject: (yylex): Convert real decimal constants directly to the precision specified by the letter at the end of the number. Pass mode arg to REAL_VALUE_ATOF to specify precision. Move the "out of range of double" error check. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@3936 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/c-lex.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'gcc/c-lex.c') diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 3fbe3d715d8..0504800ea83 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -1398,36 +1398,27 @@ yylex () else { set_float_handler (handler); - value = REAL_VALUE_ATOF (token_buffer); - set_float_handler (NULL_PTR); - } -#ifdef ERANGE - if (errno == ERANGE && !flag_traditional && pedantic) - { - /* ERANGE is also reported for underflow, - so test the value to distinguish overflow from that. */ - if (REAL_VALUES_LESS (dconst1, value) - || REAL_VALUES_LESS (value, dconstm1)) - { - pedwarn ("floating point number exceeds range of `double'"); - exceeds_double = 1; - } - } -#endif + +/* The second argument, machine_mode, of REAL_VALUE_ATOF tells the + desired precision of the binary result of decimal-to-binary conversion. */ /* Read the suffixes to choose a data type. */ switch (c) { case 'f': case 'F': type = float_type_node; - value = REAL_VALUE_TRUNCATE (TYPE_MODE (type), value); - if (REAL_VALUE_ISINF (value) && ! exceeds_double && pedantic) + value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type)); + if (REAL_VALUE_ISINF (value) && pedantic) pedwarn ("floating point number exceeds range of `float'"); garbage_chars = -1; break; case 'l': case 'L': type = long_double_type_node; + value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type)); + if (REAL_VALUE_ISINF (value) && pedantic) + pedwarn ( + "floating point number exceeds range of `long double'"); garbage_chars = -1; break; @@ -1436,7 +1427,28 @@ yylex () error ("more than one `i' or `j' in numeric constant"); imag = 1; garbage_chars = -1; + break; + + default: + value = REAL_VALUE_ATOF (token_buffer, TYPE_MODE (type)); + if (REAL_VALUE_ISINF (value) && pedantic) + pedwarn ("floating point number exceeds range of `double'"); } + set_float_handler (NULL_PTR); + } +#ifdef ERANGE + if (errno == ERANGE && !flag_traditional && pedantic) + { + /* ERANGE is also reported for underflow, + so test the value to distinguish overflow from that. */ + if (REAL_VALUES_LESS (dconst1, value) + || REAL_VALUES_LESS (value, dconstm1)) + { + pedwarn ("floating point number exceeds range of `double'"); + exceeds_double = 1; + } + } +#endif /* Note: garbage_chars is -1 if first char is *not* garbage. */ while (isalnum (c) || c == '.' || c == '_' || (!flag_traditional && (c == '+' || c == '-') -- cgit v1.2.1