f



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
Jon
5/5/2004 8:38:36 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8506) is leader. Post Follow

1 Replies
364 Views

Similar Articles

[PageSpeed] 46

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
Ben
5/14/2004 9:07:49 PM
Reply:

Similar Artilces:

Floating-point to fixed-point samples in C/C++
Hi, I have to use C/C++ to convert the floating-point to fixed-point with 1 bit-length. I am looking for algorithm and samples in C/C++ which show ho to solve this issue. I read Randy Yates' paper a http://home.earthlink.net/~yatescr/fp.pdf. But it is not easy for me t implement. Your helps are appreciated. Thanks, Vu This message was sent using the Comp.DSP web interface o www.DSPRelated.com yea that article seems 12 times longer then it should be, and when you start seeing symbols that are impossible to reproduce with pencil and paper or need a equation editor in Word you know yo...

Formatting of Inf floating-point values
While debugging some problems of my own, I stumbled on this curiosity: $ set tcl_patchLevel 8.5.8 $ set f [expr 1.0/0.0] Inf $ format %f $f 1.#INF00 Is this right/expected/documented? I couldn't find anything about Inf or Nan in the [format] man pages. This is on Windows; is it perhaps a quirk of the underlying C library? On Linux I only have Tcl8.4, where [expr] doesn't let me do divide-by-zero, but its [format %f Inf] yields "inf" as I would expect (isn't that what the C standard says?). thanks -- Jonathan Bromley On 24 aug, 10:58, Jonathan Bromle...

Formatting floating point values in ostream objects
This C program: #include <stdio.h> #include <math.h> int main() { float value; for(value = -1.0f; 1.1f > value; value += 0.1f){ printf("%.1f\n", value); } return 0; } Produces this output: -1.0 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 Trying to write an equivalent C++ program using ostream has proven tricky. Here is a solution I came up with: #include <iostream> #include <cmath> int main() { static const float TOLERANCE = 0.0001f; using std::cout; cout << std...

Getting float values from a formatted text file
Hi All I want to read certain values from text file and need help. My text file looks like the following 32 Fed 2044 25:61:61 Asdfg-Asdfg Data Unavailable Yaqw (UUUUU) Qwe (321) (deg) Asdfg (321) (deg) Yxcv (321) (deg) ----------------------- --------------- ----------------- ---------------- 32 Def 2022 10:00:00.040 56.001 -0.001 0.137 32 Def 2022 10:00:00.060 56.000 -0.001 0.112 32 Def 2022 10:00:00....

floating point zero value from c-faq.com
In http://c-faq.com/malloc/calloc.html comp.lang.c FAQ list =B7 Question 7.31 is present. In the answer to the question, part of the answer is calloc's zero fill is all-bits-zero, and is therefore guaranteed to yield the value 0 for all integral types (including '\0' for character types). But it does not guarantee useful null pointer values (see section 5 of this list) or floating-point zero values. My Question on this: Here it is mentioned that calloc's zero fill does not guarantee floating-point zero values. But when every bit of an object is set to zero, won't the o...

hex value ==> floating point value
Question: For our GPS application I need to convert the minutes part (heximal value) to a decimal/floating point value. So: 41609218 (4 bytes) has to be converted to: 14.034 (approx) (format of the float is IEEE-754 ) Thanx in advance for any help!!!! Quarco "Q" <dont@bother.com> wrote in message news:45cc5a40$0$331$e4fe514c@news.xs4all.nl... > Question: > > For our GPS application I need to convert the minutes part (heximal value) > to a decimal/floating point value. > > So: 41609218 (4 bytes) has to be converted to: 14.034 (approx) > >...

Convert floating point values to fixed point?
Hello, I want to try using an fixed point based FFT routine instead of the current floating point based routine. I have a user of my software that has a 800 Mhz VIA chipset motherboard, and the FPU on that thing is so bad, it can't crunch an audio signal in real time (i.e. - while they are talking). On non-VIA systems the computer is able to keep up in real time (it's a speech recognition app.) I found the KISS FFT project on SourceForge which is able to do fixed point FFT as well as floating point http://sourceforge.net/projects/kissfft/ However, when I use it compiled with fixe...

Fixed-point format for floating-point numbers
Dear All, Please how can I fix the significant places (number of digits after the float point) for the floating-point numbers in java? Thanks In Advance. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Motaz Khalid Saad. Department Of Computer Science Information Technology College Islamic University - Gaza - Palestine http://www.iugaza.edu.ps http://www.geocities.com/motsad e-mail: motaz.saad@gmail.com , motsad@yahoo.com ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On 3 Nov 2005 14:52:52 -0800, "Motaz Saad" <motaz.saad@gmail.com> wrote, quoted or indirectly quoted someone who said...

Query on existence of a proposal for the inclusion of an infinite precision floating point type/class into the C++ Standard/TR2
Hello all, This is my first time posting here so pardon if I lack any etiquette. Anyway, I would like to ask if there was any paper submitted to the C++ Standards Committee with regards to an infinite precision floating point type or class, or if there are any plans to do so. A brief check on the papers available on http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ did not reveal anything, though I may have accidentally overlooked some items. I understand that there is already a proposal submitted with regards to infinite precision integers ("Proposal for an Infinite Precisio...

floating point 2 floating point!!
Hi, Does anyone know how modify the exponent and mantissa word length arbitrarily in Matlab? Cheers Thomas On Fri, 20 Feb 2004 12:58:27 +0100, "Heureka" <stoltzo@hotmail.com> wrote: >Hi, > >Does anyone know how modify the exponent and mantissa word length >arbitrarily in Matlab? You can't! MATLAB has (limited) support for single precision, but if you need arbitrary precision you need the Symbolic Toolbox. Lars Lars Gregersen COMSOL A/S http://www.comsol.dk Hej Lars, Tak for dit responsum! Cheers Thomas Stoltz "Lars Gregersen" &l...

Metastock Date Format (Microsoft Binary Floating Point Format)
Hi I'm working on a program in Clipper 5.2d that reads Metastock data files and then does various stuff with the extracted data. Fortunately I found a document titled, unsurprisingly, 'MetaStock File Format' by someone called Gianluca Scacco (http:// www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/m/ms/mstockfl/MetaStock.pdf) and with the information therein have worked out most of what I need to know, except how to decode the date values. According to Mr Scacco's excellent document, date values are stored as four bytes and are of type "Float CVS"...

writing decimal values to z.-formatted fixed point values
Hello all I find myself in the situation of having to write a value of, say, -2146.9 as -0000002146900 to a text file, where the number of decimal digits is fixed and known (3 in the example). Is there a convenient SAS format to do this ? Thank you very much indeed Daniele Perhaps something like.... proc format; picture dmz /*12345678901234567890*/ low-<0 = ' 9999999999999' (mult=1e3 prefix='-') 0-high = ' 9999999999999' (mult=1e3) ; run; data _null_; x = -2146.9; y = x * 1e3; put y= z14.; put x=dmz.; ...

Value Representation: Decimal String fixed-point vs floating-point
As per DICOM Standard 2015c, Table 6.2-1. DICOM Value Representations[*] we have the following dual definition for VR=DS: [...] A string of characters representing *either* a fixed point number *o*r a floating point number. (*) A fixed point number shall contain only the characters 0-9 with an optional leading "+" or "-" and an optional "." to mark the decimal point. (*) A floating point number shall be conveyed as defined in ANSI X3.9, with an "E" or "e" to indicate the start of the exponent. [...] If I am reading this correctly: &qu...

floating point programming: c/c++ vs matlab vs fortran vs ???
Dear all, I am helping someone code a model of an optical amplifier in C code (with the aim of verifying results published by someone else). The model seems to behave correctly for a limited range of parameters, but is quite off outside this range. This is unacceptable; AFAICT theres no algorithmic reason the model should fail, so I suspect things are going wrong in floating point land. As I've been reading up on the matter I find there is a lot that could be going wrong: floating point exceptions, rounding errors etc. The model can be run reasonably quick, so we'd happily sacrifice ...

Web resources about - Standard Text Format for Floating Point Values? - comp.lang.c++.moderated

Standard - Wikipedia, the free encyclopedia
St. Catharines Standard , a St. Catharines, Ontario, newspaper Text is available under the Creative Commons Attribution-ShareAlike License ;additional ...

Aiken Standard - Local News Updated throughout the Day
Your Source for local news in Aiken, South Carolina. Visit our site for recent updates, video, breaking news, and much more.

Business Standard :: Business News,Finance News, World Business, India Stock News, Indian stock market ...
Business Standard, Indias leading business newspaper, provides latest news on stock markets, investing, companies, industry, banking, finance, ...

Leader Standard
Former England striker Beattie, a former team-mate of Monk's at Southampton, was appointed first-team coach this summer, with his prime responsibility ...

Manila Standard Today - Latest News in the Philippines
Manila Standard Today - Latest News in the Philippines

The Weekly Standard - A Weekly Conservative Magazine and Blog of News and Opinion.
The Weekly Standard - A Weekly Conservative Magazine and Blog of News and Opinion.

Bulletin Standard
Breaking USA News & Headlines; Latest News and Current News from America, New York, Los Angeles, Chicago, Houston, Philadelphia, Phoenix, San ...

Sporting codes to provide equal travel standards
Sports Minister Sussan Ley warns the nation's 30 top-funded sports organisations they could lose Australian Sports Commission investment unless ...

Chip Wilson Rips Reporter For Being On ‘Jewish Standard Time,' Tells Media It's Not News 3
... is a media "manufactured fantasy." Lululemon founder Chip Wilson doesn’t think his comment that a New York Times journalist is on “Jewish standard ...

Standard Of Review: The Times They Are A-Changin’; Will Suits Adapt?
The midseason premiere certainly feels like Suits playing its last hand to attempt to stay relevant, writes culture columnist Harry Graff.

Resources last updated: 2/9/2016 11:54:25 AM