News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

is it a c++ number ?

Started by TouEnMasm, September 13, 2014, 10:40:57 PM

Previous topic - Next topic

jj2007

Thanks. "For C and C++, octal numbers (base 8 ) begins with a zero" sounds like a can of worms, since "0123" is a valid decimal, too, and octal numbers are very rare nowadays 8)

TouEnMasm

Quote
I've seen that your above code must reworked because it:
- does reject valid FP numbers starting with a dot (e.g. ".123")
- accepts invalid octal numbers like "0123456789"
- does not recognized the "u" for MSVC integer suffixes (e.g. "uI32")
- accepts "0b", which is invalid
...

corrected in my code sample
Yours had some problems with real at end of list

http://masm32.com/board/index.php?topic=3601.msg37912#msg37912

Fa is a musical note to play with CL

qWord

Quote from: ToutEnMasm on September 15, 2014, 04:07:32 AMYours had some problems with real at end of list
which one exactly? "-1.18E - 38" is not a valid literal (the compiler recognize that as "-unary 1.18Einvalid -operator38int")

EDIT: just some more stuff you latest code wrongly interpret:
- "0x" is accepted
- "0x.0p0" is not accepted (as said, when targeting C++ this format is not required)
- "0x123fff.ffae+23" is accepted
- suffix "i9" for integers is accepted
- ".9u" is accepted (invalid FP suffix)
- ".E-1" is accepted (at least on digit is required for the mantissa)
MREAL macros - when you need floating point arithmetic while assembling!

TouEnMasm

The "-1.18E - 38" is a limit and a valid littteral.
the strtod function return -1.18000 as value.

try:
Quote
      x = strtod( string, &stopstring );
      printf( "string = %s\n", string );
      printf("   strtod = %f\n", x );
      printf("   Stopped scan at: %s\n\n", stopstring );

and you get:

Quote
string = -1.18E - 38
   strtod = -1.180000
   Stopped scan at: E - 38

The i9 is reject by the compiler because he don't know a 9 bits register,I had only take care of the form.

Fa is a musical note to play with CL

qWord

Quote from: ToutEnMasm on September 15, 2014, 04:24:14 PM
The "-1.18E - 38" is a limit and a valid littteral.
not sure what you are trying to archive, but  yes, until "E" is valid. However, you will not fined any C or C++ compiler that accepts "-1.18E - 38".

Just as side note, after looking into the C99 standard, I've recognized that these hexadecimal floating point literals must always have a exponent: .e.g. "0x1.0p0" (just "0x1.0" would be invalid). Even this rule makes sense, because otherwise the f-suffix (float) would become ambiguous.
MREAL macros - when you need floating point arithmetic while assembling!

qWord

Quote from: MichaelW on September 14, 2014, 11:20:07 PM
The attachment contains a recent adaptation of some old code that I use to verify that an input string, that is supposed to represent a double, is correctly formatted.
[..]
    static char pats[18][7] = {"d","pd","sd","ded","dpd","spd","desd",
                               "pded","sded","sdpd","dpded","pdesd",
                               "sdesd","spded","dpdesd","spdesd",
                               "sdpded","sdpdesd"};
Really nice idea! Looks a bit like regular expressions :biggrin:

MREAL macros - when you need floating point arithmetic while assembling!

TouEnMasm

Quote
However, you will not fined any C or C++ compiler that accepts "-1.18E - 38".

No need to search,it is vc express edition 2010.
Fa is a musical note to play with CL

qWord

Quote from: ToutEnMasm on September 16, 2014, 02:11:01 AM
Quote
However, you will not fined any C or C++ compiler that accepts "-1.18E - 38".

No need to search,it is vc express edition 2010.
I thought you want validate input from a c++ (or c) source file...
MREAL macros - when you need floating point arithmetic while assembling!