Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #10715
| From | Bart van Ingen Schenau <bart@ingen.ddns.info> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: floating point conversions && how to read standards |
| Date | 2011-10-07 11:23 +0200 |
| Organization | No organisation in particular |
| Message-ID | <j6mgei$bfq$1@localhost.localdomain> (permalink) |
| References | <5577162f-18ea-4f37-bd7a-c8f375c71d41@d18g2000yql.googlegroups.com> |
Stanley Rice Wrote: > Hi all, I got confused while referencing to the 4.8/1 in draft n3242. > > 4.8 Floating point conversions > A prvalue of floating point type can be converted to a prvalue of > another floating point type. If the source value can be exactly > represented in the destination type, the result of the conversion is > that exactly representation. If the source value is between two > adjacent destination values, the result of the conversion is an > implementation-defined choice of either of those values. Otherwise, > the behavior is undefined. > > I do not exactly know what the 'destination type' and 'two adjacent > destination value' mean. Could you explain to me and show me some > example if possible. Lets assume, for the purpose of this explanation, that you have a system where double can represent 3 decimal digits of precision and float can represent 2 decimal digits of precision. On such a system, if you have the initialisation float pi = 3.14; the constrant 3.14 (of type double) has to be converted to type float. This makes float the 'destination type' of clause 4.8. As float can not represent the value 3.14 exactly (given that float can only represent 2 digits), the compiler has to round the value to one that can be represented in float. This would be either 3.1f or 3.2f, which are the two nearest representable values. > > What's more, I found reading the standard is quite difficult. There > are so many new terms that were never heard before. I have to > keep cross referencing, which in return, I forget where I got started. > Is there experienced ones who can give me some suggestions > about how to read standards. Reading standards is not for the faint of heart. They are not meant as a teaching aid, but are more like a law-text. The only advice I can give is to keep practicing. With practice, the common terms and the phraseology become more familiar. Bart v Ingen Schenau
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
floating point conversions && how to read standards Stanley Rice <heconghui@gmail.com> - 2011-10-07 00:55 -0700
Re: floating point conversions && how to read standards Juha Nieminen <nospam@thanks.invalid> - 2011-10-07 08:05 +0000
Re: floating point conversions && how to read standards Stanley Rice <heconghui@gmail.com> - 2011-10-08 00:18 -0700
Re: floating point conversions && how to read standards Robert Wessel <robertwessel2@yahoo.com> - 2011-10-08 02:36 -0500
Re: floating point conversions && how to read standards Bart van Ingen Schenau <bart@ingen.ddns.info> - 2011-10-07 11:23 +0200
Re: floating point conversions && how to read standards Stanley Rice <heconghui@gmail.com> - 2011-10-08 00:30 -0700
csiph-web