Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.development.apps > #449
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!solaris.cc.vt.edu!news.vt.edu!newsfeed-00.mathworks.com!panix!not-for-mail |
|---|---|
| From | Grant Edwards <invalid@invalid.invalid> |
| Newsgroups | comp.os.linux.development.apps |
| Subject | Re: cast double to short problem |
| Date | Wed, 7 Mar 2012 15:23:39 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 29 |
| Message-ID | <jj7uhr$prg$1@reader1.panix.com> (permalink) |
| References | <jj64g2$fb8$1@dont-email.me> <jj6650$fa0$1@reader1.panix.com> <jj6714$tbh$1@dont-email.me> <jj6a7s$l7k$1@reader1.panix.com> <jj7cii$ahl$1@dont-email.me> |
| NNTP-Posting-Host | dsl.comtrol.com |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Trace | reader1.panix.com 1331133819 26480 64.122.56.22 (7 Mar 2012 15:23:39 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Wed, 7 Mar 2012 15:23:39 +0000 (UTC) |
| User-Agent | slrn/pre0.9.9-102 (Linux) |
| Xref | csiph.com comp.os.linux.development.apps:449 |
Show key headers only | View raw
On 2012-03-07, Noob <root@127.0.0.1> wrote:
> Grant Edwards wrote:
>
>> $ man round
>> #include <math.h>
>> i = (short) round(MyDoubleValue * 100.0);
>
> Depending on so-called rounding modes, some CPUs do not round as
> mathematicians expect.
IMO, depending on 1.5 or 2.5 being rounded one way or the other is a
bug, but I realize that in some statistical applications it matters.
However, the CPU type should have nothing to do with it -- the
behavior of the libm round() function is well defined to "round
halfway cases away from zero". If you want half-way values to round
to nearest even then the round() man page says that you should call
rint().
> See, for example, the "nearest even" mode where both 1.5 and 2.5
> (which can be represented exactly in binary FP) are rounded to 2.
>
> http://www.ocf.berkeley.edu/~horie/rounding.html
--
Grant Edwards grant.b.edwards Yow! PARDON me, am I
at speaking ENGLISH?
gmail.com
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