c++ - What information is used when parsing a (float) number? -


what information standard library of c++ use when parsing (float) number?

here's possibilities know parse (single) float number std c++:

it seems obvious, at least, have know character used decimal separator.

iostreams, in particular num_get::get, in addition talk about:

  • ios_base i/o format flags - is there any information here used when parsing floating point?
  • the thousands_separator (* see below)

on other hand, in std::strtod, seems sscanf defined in terms of (which in turn referenced num_get), there variable information seems considered space , decimal character, although doesn't seem specified that defined. (at least neither on cppref nor on msdn.)

so, information used, , comprises valid parseable float representation c++ standard lib?

from see, decimal separator global (cor c++ ???) needed and, in addition, if number contains thousands separator, expect parsed correctly num_get since strod/sscanf not support thousands separator.


(*) group (thousands) separator interesting case me. far can tell "c" functions not make any reference , last time checked c , c++ standard printf function never write it. processed strtod/scanf functions? (i know there posix printf extension group separator, that's not standard, , notably missing microsoft's implementation.)

the c11 spec strtod() seems have opening big enough size truck drive through. appears open ended, see no limitation.

§7.22.1.3 6 in other "c" locale, additional locale-specific subject sequence forms may accepted.


for non- "standard c" locales, isspace(), decimal (radix) point, group separator, digits per group , sign seem constitute typical variants. apparently there no limit.


for fun experimented 500+ locales using printf(), sscanf(), strftime() , isspace().

all tested locales had radix (decimal) point of '.' or ',', same +/- sign, no digit grouping, , expected 0-9.

strftime(... "%y" ...) did not use digit separator on years 1000-99999.

sscanf("1,234.5", "%lf", .. , sscanf("1.234,5", "%lf", .. did not produce 1234.5 in locale.

all int values in range 0 255 produced same isspace() results exception of 154 , 160.

of course these test not prove limit may occur, represent sample of possibilities.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -