#### 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 10705 articles. 11 followers. allnor (8507) is leader.

1 Replies
259 Views

Similar Articles

[PageSpeed] 5
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
Similar Artilces:

How to plot standard deviation errors over the bars?
Hello, I have some data in vectors x and y. I can make their bar plot using bar(x,y). I also have some standard deviation stored in vector e. Now, when I use errorbar(x,y,e) it plots what I need but there are no bars but rather points with +- e. What I need is bars like from the bar command and error plotted over the bars. How can this be achieved? Thank you. On 7/17/2013 5:36 AM, Muhammad wrote: .... > I have some data in vectors x and y. I can make their bar plot using > bar(x,y). I also have some standard deviation stored in vector e. Now, > when I use errorbar(x,y,e)...

what is the error in:window.opener.document.EditView+".participant_id_"+index.value = id;?
I wan to use a function(blow) to set value for an elment of parent window,and the id of this element is a combination of string +variable,the question is how to contruct this id,when I create it as blow,got an error:invalid assignment left-hand side(firebug) ,So can anybody help me? --------------------------------------------------------------------------------------------------------------------------------------- function setUser(index,id){ window.opener.document.EditView+".participant_id_"+index.value = id; window.close(); } ------------------------------------------------...

Standard Versus Non-Standard C++
{ Reformatted; please limit your lines to 70 characters -mod } Hi All, I asked a rhetorical question in a recent post, and the post was rejected, perhaps because I did not explain why I was asking the question. The question was: "Is this valid C++ code or not?" "this" was code like: // Is this C++? SyndicationClient^ client = ref new SyndicationClient(); for(wstring url : urls) // Perhaps it is, and my compiler is simply out of compliance. ....found on this page: http://msdn.microsoft.com/en-us/library/windows/apps/hh465045.aspx The Mo...

How to convert a C "char *" value to Ada string?
How to convert a C "char *" value to Ada string? There is function To_Ada (Item : in char_array; Trim_Nul : in Boolean := True) return String; in package Interfaces.C, but it receives an array not a pointer (= access). So I don't understand how to do this simple thing. -- Victor Porton - http://portonvictor.org Victor Porton wrote: > How to convert a C "char *" value to Ada string? > > There is > > function To_Ada (Item : in char_array; > Trim_Nul : in Boolean :=...

Timestamp field ignores supplied value
I'm doing a INSERT...SELECT and one column in the source table is a datetime field with the target column being a timestamp format. I'm changing the format because I can easily switch between timezones with the latter rather than the former. However, instead of copying the value from the source column to the target column it inserts the current date and time. There are 13 million rows but no warnings or errors are issued. I've tried it with a small experiment, see below, and it works as expected. Ideas/solutions welcome. MySQL> create table tmp (DateTime datetime); Query OK, ...

RE: text file edit object #2
#- Not to mention the fact that you can't write to myfile as #- defined. ;-) How #- about something like (not tested): Jajaja, sorry. Very stupid, didn't open the file for writing, :p #- import os, sys #- #- try: #- infile = file("foo.txt", "r") #- lines = infile.readlines()[:-10] #- infile.close() #- except IOError: #- print >> sys.stderr, "edit failed" #- else: #- try: #- outfile = file("foo.txt.new", "w") #- outfile.writelines(lines) #- ...

Is printing black text only on a color printer more expensive than using a dedicated monochrome laser?
Basically, I need to replace our old businesses HP4 and I'm trying to determine if I should get a dedicated monochrome laser and a color laser so I can split the tasks between them or should I just get a single printer and send all color and b&w jobs to it. I don't want to buy a single printer if my operating costs for printing b&w on it will be much higher. So, as a rule, is printing black text only on a color laser printer more expensive than using a dedicated monochrome laser? Have the falling prices of color lasers leveled off now and the technology advance...

returning text in GUI
Simple question here: does anyone know how to create an object in a GUI where text can be returned in for display? For example, if I was constructing a simple calculator with matlab-gui, how would I specify arithmetic results to be returned in the top display? Joe Hi, see example there : Kristina Arianson, "Continously changing, non-interactive text in GUI" #, 20 Apr 2006 8:10 am </WebX?14@@.ef315c9> J�r�me ...

Replacing selected text in textarea
Hello, I like to replace selected text in a textarea or insert text on the cursors location. Is this possible with javascript? If yes how to do this and does this work on all major browsers? Thanks in advance Rob ...

Re: Interleaving graphs and tables by BY-values: Proc Document?
On Wed, 19 Sep 2007 12:07:38 -0500, Matt Pettis <matt.pettis@THOMSON.COM> wrote: >Hi, > >I have two datasets that have the same BY-values in them. One is a >summary off of which I make tables (using Proc Print, Tabulate, or >Report), the other table has data that I want to graph with Proc Gplot. >I would like to interleave them so that for each BY-value level >combination, I have the corresponding graph followed by the >corresponding table(s) for the levels of a given BY-group. > >I am considering making a macro that can be called on each combination >o...

Print "text" on a figure help!!!
Hi all, I am running a for loop in Matlab where I plot a Figure and everytime the iteration increases, the figure is updated. I would like while I am looking at the figure (as it goes through every iteration) to see something like:Snapshot: 1.On the next iteration Snapshot: 2 ...,3,4 and so on. How can I print something like this on a Figure?? Thanks a lot Regards Alex "General" <mammasis82@hotmail.com> wrote in message news:14085674.1197037485957.JavaMail.jakarta@nitrogen.mathforum.org... > Hi all, > > I am running a for loop in Matlab where I plot a Figure a...

function dy = prob_52 (t,y) dy = cos(y) - (sin (t)*y); [t,y] = ode45 (@prob_52,[0,1],0) plot (t,y) xlabel ('Time') ylabel ('Function Value') "Nikki Smith" <newe0033@umn.edu> wrote in message news:iaaaid$48t$1@fred.mathworks.com... > function dy = prob_52 (t,y) > dy = cos(y) - (sin (t)*y); > > [t,y] = ode45 (@prob_52,[0,1],0) > plot (t,y) > xlabel ('Time') > ylabel ('Function Value') So what is the FULL TEXT of the error message you receive? How are we supposed to help you without that? As a _guess_ I'd say...

C++/CLI standard
I have initiated a similar discussion thread in clc++m, however because of the "m" in the name, the discussion is progressing slowly, so I am setting another thread here. Well the story is this. There is an official ISO standard about CLI runtime environment, which is about a standardised *multilingual* virtual machine environment together with its assembly language. There are two CLI compliant virtual machines today, .NET framework in the Windows world, and Mono in GNU/Linux. There is also an official ISO C#/CLI standard that describes C# and how it works in CLI environ...

siunitx table-format and table-column-width
Hello, \documentclass{article} \usepackage [T1]{fontenc} \usepackage {siunitx}% loads array.sty \begin{document}\makeatletter \begin{tabular}{ | S [table-format=8.2] | S[table-format=6.2,table-column-width=22mm] | } 3254346.324 & 325436.3255 \\ 3254346.324 & 325436.3255 \\ \end{tabular} \end{document}\endinput Questions: 1) Is this on purpose that table-format=8.2 does not round or truncate the number to 2 decimals ? well it seems to be "table-auto-round" 2) Though I understand and see a difference when i set table-column-width to some judiciou...

[TDBC] How to get the return value
Hi, after executing something like set call [db preparecall { :result = call FND_WEB_SEC.VALIDATE_LOGIN(:p_user, :p_pwd) }] How can I get the result of the call. puts "result = $result" doesn't because there is no result variable. Thanks and regards, Dirk On 12/17/2010 09:38 AM, Dirk Hoffmann wrote: > Hi, > > after executing something like > > set call [db preparecall { > :result = call FND_WEB_SEC.VALIDATE_LOGIN(:p_user, :p_pwd) > }] > > How can I get the result of the call. > > puts "resu... \strikeout{text} ? I need a command \strikeout{text} similar to \underline{text}. Does it exist? Thanks, Edward Edward Goldobin wrote: > I need a command \strikeout{text} similar to \underline{text}. Does it > exist? > > Thanks, > Edward > Hi, Look at the ulem package regards, -- oups Edward Goldobin wrote: > I need a command \strikeout{text} similar to > \underline{text}. Does it exist? i believe there is a package that provides it, though i don't remember which one. i use a small piece of code that i once found on the internet (i have no idea how it works...): \newl... How to change the text of Address bar? Hello all, Is it possible to change the text of Address bar when i click on any link. Does any one knows the script to do this. Sujan. "Sujan" <sujanrb@gmail.com> skrev i meddelandet news:1119602919.046183.219140@o13g2000cwo.googlegroups.com... > Hello all, > > Is it possible to change the text of Address bar when i click on any > link. Does any one knows the script to do this. You mean, in a way that would have the address bar say www.bankofamerica.com while actually you're visiting www.phishtank.ru? Hope it can't be done. -- Joakim Braun Sujan wr... Value List Cache The login to the display of a to doubleclick with a desktop (over the driver from Outlook)? ... snwprintf > Also is snprintf (the non-unicode version) standard ? > in either C90 or C9x ? If snprintf is standard, what are similiar results for snprintf ? i.e. char s[100]; snprintf(s,5,"Hello"); What should snprintf return ? What should be in the buffer 's' ? snprintf(s,4,"Hello"); Likewise for the above. Googler <cpp_70@yahoo.com> wrote: >> Also is snprintf (the non-unicode version) standard ? >> in either C90 or C9x ? > If snprintf is standard, what are similiar results for snprintf ? > > char s[100]; > > snprintf(s,5,"... Re: text variable to numeric #3 yes, you are right. And where is your problem??? Gerhard On Wed, 12 Aug 2009 11:41:04 -0400, Daniel Fern=?ISO-8859-1?Q?=C3=A1ndez?= <fdezdan@GMAIL.COM> wrote: >data date_numeric; >set test (drop=date); >date=mdy(month,day,year); >run; > >Dani Fernández. >Terrassa Hospital (Barcelona-Spain). ... format USB drive or stick Hello folks, When I make "Solaris2" fdisk partition it puts overlap AND one small slice with number 8 like "boot" slice on it. Since I don't plan to boot from this disk, all I want is one big slice s0 (with the same size like s2). However, format(1m) does not allow me to delete s8: partition> 8 8' is not expected. How can I remove s8? I want only s0 (and s2) and then newfs(1m) it. Why? It is annoying when vold(1m) mounts main partition and offers to format s8 every time! -- Miroslav Miroslav Zubcic wrote: > partition> 8 > 8' is not expect... Tkinter Hello I'm writing an application in Python 2.5.4 under Windows (xp sp3 en). I use Tkinter as the main GUI toolkit. The app is intended to be portable (not fully but win & mac os x is a must). It works as it should on my system, but when I've sent the program to my friend who has a mac computer, he told me accented characters are turned into weird symbols. It is another must, the GUI consists of widgets with polish characters. I always use UTF-8 encoding in Python and I save my scripts in Notepad++ as UTF-8 without BOM. I've never experienced similar problems under Windows with... Google Groups: Original Format: 404 Error Since about April 2012 I've been getting "Not Found: 404 Error" when I try to view the Original Format version of my messages in my Google Groups test group to see the headers of the message: http://groups.google.com/forum/?fromgroups#!searchin/groups-test-group/Error$20404 You can try to view the original format of a message by clicking the arrow next to the date and the "Post reply" button. This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323328-5015...

US-TX-Austin: Staff & Sr. Auditors, working knowledge of auditing standards; 2.5 (45293632412)
US-TX-Austin: Staff & Sr. Auditors, working knowledge of auditing standards; 2.5 (45293632412) ============================================================================================== Position: Staff & Sr. Auditors Reference: SMC01302 Location: Austin TX Duration: 2.5Y Skills: Staff Auditor MINIMUM QUALIFICATIONS: Bachelor's degree plus basic experience in auditing, program evaluation, policy analysis, research/data analysis, and/or legal analysis. Willing to travel up to 50%. ...

Re: using Perl regex to validate values in SAS 9.1 #11
On Mon, 6 Jun 2005 12:27:00 -0700, David L. Cassell <cassell.david@EPAMAIL.EPA.GOV> replied in part to Venky Chakravarthy's question: >> Do we really need Perl Regex? > >No. We don't. That is quite a concession from a Perl Bigot :-). > >> Shouldn't the following humble data >step, not >> achieve the same results? > >Yes. It should. > >> data wrongrecords ; >> set staff ; >> if missing(phone1) or missing(phone2) then delete ; >> if (input(phone1,??12.)=.) or (input(phone2...