Author Topic: is it a c++ number ?  (Read 21406 times)

jj2007

  • Member
  • *****
  • Posts: 13945
  • Assembly is fun ;-)
    • MasmBasic
Re: is it a c++ number ?
« Reply #15 on: September 15, 2014, 12:30:46 AM »
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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: is it a c++ number ?
« Reply #16 on: September 15, 2014, 04:07:32 AM »
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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: is it a c++ number ?
« Reply #17 on: September 15, 2014, 04:38:34 AM »
Yours 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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: is it a c++ number ?
« Reply #18 on: September 15, 2014, 04:24:14 PM »
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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: is it a c++ number ?
« Reply #19 on: September 16, 2014, 01:52:48 AM »
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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: is it a c++ number ?
« Reply #20 on: September 16, 2014, 01:58:47 AM »
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.
[..]
Code: [Select]
    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

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: is it a c++ number ?
« Reply #21 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.
Fa is a musical note to play with CL

qWord

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: is it a c++ number ?
« Reply #22 on: September 16, 2014, 02:44:44 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!