Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #451
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: cast double to short problem |
| Date | 2012-03-07 20:13 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <jj8fi1$ggn$1@reader1.panix.com> (permalink) |
| References | <jj64g2$fb8$1@dont-email.me> <jj6650$fa0$1@reader1.panix.com> <alpine.DEB.2.00.1203071908210.1839@login01.caesar.elte.hu> |
On 2012-03-07, Ersek, Laszlo <lacos@caesar.elte.hu> wrote:
>
>> Ah, there's your problem: expecting to get 3. You should expect to
>> get either 2 or 3. And you do. :)
>
> He should get the same result both times.
Yes. He should. My point is that he shouldn't expect to.
His code should not be written to depend on either (int)(0.3 * 10.0)
== 2 or on (int)(0.3 * 10.0) == 3.
> - The floating point environment is the same.
> - dval starts out the same (as in "object representation").
> - 10 (int) is converted to double the same way (with exact value).
> - Both double multiplications happen with the same operands (as in
> "object representation").
> - Initialization of (~ simple assignment to) a double does not change the
> double product (as in "object representation").
> - Conversion to short is the same (truncated toward zero).
I agree: I think it should produce the same result in both cases.
--
Grant Edwards grant.b.edwards Yow! I'm using my X-RAY
at VISION to obtain a rare
gmail.com glimpse of the INNER
WORKINGS of this POTATO!!
Back to comp.os.linux.development.apps | Previous | Next — Previous in thread | Next in thread | Find similar
cast double to short problem Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-06 16:52 -0600
Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-06 23:21 +0000
Re: cast double to short problem Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-06 17:36 -0600
Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-07 00:30 +0000
Re: cast double to short problem Noob <root@127.0.0.1> - 2012-03-07 11:17 +0100
Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-07 15:23 +0000
Re: cast double to short problem "Ersek, Laszlo" <lacos@caesar.elte.hu> - 2012-03-07 19:33 +0100
Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-07 20:13 +0000
Re: cast double to short problem Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-08 11:45 -0600
csiph-web