Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #139430
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: A final word on casting. |
| Date | 2019-01-04 16:25 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <q0oj0b$khc$1@dont-email.me> (permalink) |
| References | (13 earlier) <kfnsgygfdsk.fsf@x-alumni2.alumni.caltech.edu> <kfnk1jof4qx.fsf@x-alumni2.alumni.caltech.edu> <H9UWD.627706$gPr.533161@fx08.am4> <tUsXD.1964$gy2.1241@fx21.am4> <3pAXD.199851$e%3.151775@fx42.iad> |
On 1/3/19 22:27, Richard Damon wrote: > On 1/3/19 1:55 PM, Bart wrote: >> >> I found that if I used 80-bit floats, then I can get results that match >> those from strtod, and those produced by gcc. (That is, given 1000 >> random floating point numbers of varying precision and range in source >> code), the compiled binary pattern matches exactly. For this set of >> numbers...) >> >> So I'm not sure what that 1000 bits is for that has been mentioned. >> 80-bit floats have only an extra 11 bits of precision. >> >> (This is experimental and done via non-portable inline ASM, but it shows >> that it can be done with only a few extra precision bits. Since the >> discrepancy was only a couple of bits, this is not surprising.) >> > > The 1000 bit value was someones calculation of the number of bits you > needed to be computing in to get absolute exact rounding of a floating > point number to double precision, i.e. the difference between the > rounded representation and the exact value represented by the string is > less than 0.50000000000000... ULP. > > I haven't looked up the math to compute that, and while at first thought > it seems high, I am not so sure as to say it must be too high. 'Random' > numbers may not get you anywhere close to the needed value, as you are > looking for the pathalogical case which gets you to looking for a > difference between something like .4999999999999999 and .50000000000 > where that small difference affects the final rounding. The most difficult case to handle is a decimal string representing a value that is almost exactly halfway between two representable values, when the current rounding mode is "round to nearest". Such a string must be processed until you can determine whether it's above, below, or equal to that half-way value. On my system, the smallest representable value greater than 1.0 is 1.0 + 2^-52, which can be represented exactly in decimal as 1.0000000000000002220446049250313080847263336181640625 The halfway point between that and 1.0 is therefore 1.00000000000000011102230246251565404236316680908203125 If you process a digit string that starts with "1.00000000000000011102230246251565404236316680908203124", there's no need to process any further, it's guaranteed that the closest representable value is 1.0. If you process a digit string that starts with "1.00000000000000011102230246251565404236316680908203125", as soon as you've processed that part of the string, you only need to check whether any of the subsequent digits is non-zero. If so, it rounds up to 1.0000000000000002220446049250313080847263336181640625 otherwise, it rounds however you handle the halfway value. If __STDC_IEC_559__ is pre#defined by the implementaiton, than the rules of IEC/ISO 60559 (== IEEE 754) apply, which require that the half-way point be rounded to set the last bit to 0, which would correspond to 1.0 in this case. Either way, there's never any need to store any data after processing the first 54 significant digits. Handling the first 54 digits might require storing a lot more than 80 bits (I'm not sure whether there's a shortcut that would allow it to be done using only a little more than 52 bits), but it requires a lot less than 1000+ bits. I can't imagine what the argument might be that calls for 1000+ bits - perhaps Tim can give us a citation of the relevant discussion he referred to? His description was not sufficiently detailed for me to locate the discussion using Google groups.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A final word on casting. chanrasjid@gmail.com - 2018-12-23 03:02 -0800
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-23 12:11 +0000
Re: A final word on casting. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-12-23 13:08 +0000
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-23 14:43 +0000
Re: A final word on casting. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-12-23 14:56 +0000
Re: A final word on casting. chanrasjid@gmail.com - 2018-12-23 07:08 -0800
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-23 15:55 +0000
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-23 16:07 +0000
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-23 08:21 -0800
Re: A final word on casting. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-12-23 17:56 +0000
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-23 19:23 +0000
Re: A final word on casting. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-12-23 20:12 +0000
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-23 14:06 -0800
Re: A final word on casting. Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-28 09:34 -0800
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-28 20:29 +0000
Re: A final word on casting. Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-28 15:07 -0800
Re: A final word on casting. Richard Damon <Richard@Damon-Family.org> - 2018-12-28 20:56 -0500
Re: A final word on casting. Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-29 09:22 -0800
Re: A final word on casting. Tim Rentsch <txr@alumni.caltech.edu> - 2019-01-01 13:27 -0800
Re: A final word on casting. Bart <bc@freeuk.com> - 2019-01-02 01:07 +0000
Re: A final word on casting. Bart <bc@freeuk.com> - 2019-01-03 18:55 +0000
Re: A final word on casting. Richard Damon <Richard@Damon-Family.org> - 2019-01-03 22:27 -0500
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-01-04 16:25 -0500
Re: A final word on casting. Ike Naar <ike@iceland.freeshell.org> - 2018-12-28 19:10 +0000
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-28 12:33 -0800
Re: A final word on casting. "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-12-23 14:11 -0800
Re: A final word on casting. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2018-12-24 02:54 -0800
Re: A final word on casting. fir <profesor.fir@gmail.com> - 2018-12-24 03:24 -0800
Re: A final word on casting. fir <profesor.fir@gmail.com> - 2018-12-24 03:29 -0800
Re: A final word on casting. fir <profesor.fir@gmail.com> - 2018-12-24 03:45 -0800
Re: A final word on casting. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-12-24 13:44 +0000
Re: A final word on casting. Richard Damon <Richard@Damon-Family.org> - 2018-12-24 08:51 -0500
Re: A final word on casting. Richard Damon <Richard@Damon-Family.org> - 2018-12-23 14:53 -0500
Re: A final word on casting. Robert Wessel <robertwessel2@yahoo.com> - 2018-12-24 09:39 -0600
Re: A final word on casting. Richard Damon <Richard@Damon-Family.org> - 2018-12-24 13:38 -0500
Re: A final word on casting. Manfred <noname@add.invalid> - 2018-12-23 21:22 +0100
Re: A final word on casting. Manfred <noname@add.invalid> - 2018-12-23 21:33 +0100
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-23 10:56 -0500
Re: A final word on casting. Sjouke Burry <burrynulnulfour@ppllaanneett.nnll> - 2018-12-23 17:18 +0100
Re: A final word on casting. Bart <bc@freeuk.com> - 2018-12-23 20:03 +0000
Re: A final word on casting. "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2018-12-28 14:47 -0500
Re: A final word on casting. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-12-23 12:24 +0000
Re: A final word on casting. Richard Damon <Richard@Damon-Family.org> - 2018-12-23 07:28 -0500
Re: A final word on casting. Tim Rentsch <txr@alumni.caltech.edu> - 2018-12-28 07:50 -0800
Re: A final word on casting. fir <profesor.fir@gmail.com> - 2018-12-23 04:35 -0800
Re: A final word on casting. fir <profesor.fir@gmail.com> - 2018-12-23 04:42 -0800
Re: A final word on casting. fir <profesor.fir@gmail.com> - 2018-12-23 04:52 -0800
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-23 10:28 -0500
Re: A final word on casting. Barry Schwarz <schwarzb@dqel.com> - 2018-12-23 11:39 -0800
Re: A final word on casting. Ike Naar <ike@iceland.freeshell.org> - 2018-12-24 07:56 +0000
Re: A final word on casting. chanrasjid@gmail.com - 2018-12-24 14:03 -0800
Re: A final word on casting. Barry Schwarz <schwarzb@dqel.com> - 2018-12-24 14:39 -0800
Re: A final word on casting. chanrasjid@gmail.com - 2018-12-24 14:50 -0800
Re: A final word on casting. Keith Thompson <kst-u@mib.org> - 2018-12-24 15:34 -0800
Re: A final word on casting. Keith Thompson <kst-u@mib.org> - 2018-12-24 15:23 -0800
Re: A final word on casting. chanrasjid@gmail.com - 2018-12-24 20:34 -0800
Re: A final word on casting. Keith Thompson <kst-u@mib.org> - 2018-12-24 14:52 -0800
Re: A final word on casting. chanrasjid@gmail.com - 2018-12-24 20:25 -0800
Re: A final word on casting. James Kuyper <jameskuyper@alumni.caltech.edu> - 2018-12-24 17:52 -0500
Re: A final word on casting. luser droog <luser.droog@gmail.com> - 2018-12-24 21:27 -0800
Re: A final word on casting. luser droog <luser.droog@gmail.com> - 2018-12-24 21:39 -0800
Re: A final word on casting. chanrasjid@gmail.com - 2018-12-24 22:36 -0800
csiph-web