|
|
Standard Text Format for Floating Point Values?
I have noticed a great deal of variance between various run time
libraries for C++ compilers in how floating point values (floats and
doubles) get formatted when they represent "invalid" values such as
plus or minus infinity or not a number. I work with applications
where the presentation of such data is rather important and find
myself frustrated that, even with the same library, I cannot write out
such a value as text to a stream and expect it to be read from that
stream as the same value. My question is whether there is any
standard for describing these type of values as text. If there is
such a standard, I would like my output to conform to it. Failing
that, I suppose that I will use my own formatting rules so that my
programs produce reliable output.
Thanks,
Jon Trauntvein
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Jon
|
5/5/2004 8:38:36 PM |
|
Jon Trauntvein wrote:
> I have noticed a great deal of variance between various run time
> libraries for C++ compilers in how floating point values (floats and
> doubles) get formatted when they represent "invalid" values such as
> plus or minus infinity or not a number.
So far as I am aware, formatting of non-numbers is either unspecified
or undefined in C++. (Formatted output is mostly defined in terms of
printf as specified in C90, but it is difficult and expensive to get
hold of that standard now.)
> I work with applications where the presentation of such data is
> rather important and find myself frustrated that, even with the same
> library, I cannot write out such a value as text to a stream and
> expect it to be read from that stream as the same value.
Unfortunately the standard does not allow more liberal parsing of
numbers, probably because that could break code like this:
int i;
std::string s;
if (is >> i)
process_number(i);
else if (is >> s)
process_string(s);
> My question is whether there is any standard for describing these
> type of values as text. If there is such a standard, I would like
> my output to conform to it. Failing that, I suppose that I will use
> my own formatting rules so that my programs produce reliable output.
C99 specifies many more aspects of floating-point handling in the
language and library, many of which I think are likely to make it into
a future C++ standard.
Quoting from the final draft of C99 (not the actual standard), on
output through printf(),
"A double argument representing an infinity is converted in one of
the styles [-]inf or [-]infinity -- which style is implementation-
defined. A double argument representing a NaN is converted in one
of the styles [-]nan or [-]nan(n-char-sequence) -- which style,
and the meaning of any n-char-sequence, is implementation-defined."
This goes for e, f and g specifiers; the E, F and G specifiers result
in upper-case letters instead. On input through fscanf(), all of the
possible implementation-defined output formats must be accepted case-
insensitively. The optional n-char-sequence following "nan" is an
arbitrary long sequence of characters 0-9, A-Z, a-z and _.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Ben
|
5/14/2004 9:07:49 PM
|
|
|
1 Replies
113 Views
(page loaded in 0.044 seconds)
Similiar Articles: Floating Point and printf() - comp.lang.asm.x86... floating point values ... The value is: %f",0xA,0 val dd 1323.23 segment .text ... FORMAT STRING SYMPTOMS: I understand that the single precision floating-point values only ... Convert from std_logic_vector to real - comp.lang.vhdlThe problem lies in the fact that you can represent real values in different ways as bits. The IEEE floating point format defines a standard doing this for single/double ... set format of decimal point global? - comp.soft-sys.matlab ...Anyway, you cannot change the standard inside ... for Floating Decimal Points | eHow.com Java Format for Floating Decimal Points. Floating decimal point ... decimal value ... Max integer in a floating point type? - comp.lang.c++.moderated ...Using the actual radix of the floating point > format (should it not ... The first is that the standard allows intermediate floating point values to use extended formats ... Variations On Formats On Arithmetic Scalar Types - comp.lang.c++ ...Does C++ Standard prescribe underlying ... model for a generalized floating point format, and ... 10-byte) packed BCD integer values. Arithmetic is done in the native format ... I have a isNumeric function to check a text field is numeric .. I ...... All JavaScript Numbers are stored in float format. ... test an ECMAScript Number value for being a > floating-point value ... I have a isNumeric function to check a text field ... code to convert negative fractions to binary - comp.soft-sys ...They are already in memory in binary floating point format, so what ... about _which_ binary representation you want for your negative values. Standard IEEE floating point ... imhist - comp.soft-sys.matlab... for use with greyscale i= mages, which in the standard uint8 format only ... Now let's synthesize an image that is a floating point % image and has values from -12345 to ... Static const integral data members can be initialized? - comp.lang ...... is called to generate the constant in the format ... If floating point values can be compile time constants, can they ... I also think that the standard should not require ... awk and floating point arithmetic - comp.unix.solarisAcrobat 6 Pro Math.round function - comp.text.pdf awk and floating point arithmetic ... point arithmetic - comp.lang.awk This is the output format specifier for numeric values ... Floating point - Wikipedia, the free encyclopediaFloating-point representation, in particular the standard IEEE format, is by far the most ... Double extended format, 80-bit floating point value. ... Text is available under ... IEEE Floating Point Data - MAST... data within the FITS format using the IEEE (1985) standard. This Floating Point ... The text of the Floating Point Agreement (Wells ... carefully with floating point values ... 7/18/2012 12:19:30 PM
|
|
|
|
|
|
|
|
|