* calculation error with built-in command CTRL + J?!
@ 2008-04-14 3:59 Borde, Andreas
2008-04-14 6:11 ` David Hansen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Borde, Andreas @ 2008-04-14 3:59 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I calculated
(* 12 2.6) with the built in command CTRL + J and got
31.200000000000003
It is the same for
(* 2.6 12)
I am wondering about the tailing numbers after 31.2!
If I calculate (* 2.5 12) then the result is the expected 30.0.
Can someone tell me the reason? Is there something wrong with
my calcuation?
I am using the official release:
This is GNU Emacs 22.1.1 (i386-mingw-nt5.0.2195)
of 2007-06-02 on RELEASE
under Win2k.
Thank you and kind regards
Borde, Andreas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calculation error with built-in command CTRL + J?!
2008-04-14 3:59 calculation error with built-in command CTRL + J?! Borde, Andreas
@ 2008-04-14 6:11 ` David Hansen
2008-04-14 6:24 ` Thierry Volpiatto
2008-04-14 6:40 ` Sven Joachim
2 siblings, 0 replies; 4+ messages in thread
From: David Hansen @ 2008-04-14 6:11 UTC (permalink / raw)
To: help-gnu-emacs
On Mon, 14 Apr 2008 12:59:10 +0900 Andreas Borde wrote:
> Can someone tell me the reason? Is there something wrong with
> my calcuation?
Normal floating point rounding error.
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calculation error with built-in command CTRL + J?!
2008-04-14 3:59 calculation error with built-in command CTRL + J?! Borde, Andreas
2008-04-14 6:11 ` David Hansen
@ 2008-04-14 6:24 ` Thierry Volpiatto
2008-04-14 6:40 ` Sven Joachim
2 siblings, 0 replies; 4+ messages in thread
From: Thierry Volpiatto @ 2008-04-14 6:24 UTC (permalink / raw)
To: Borde, Andreas; +Cc: help-gnu-emacs
"Borde, Andreas" <andreas.borde@jp.bosch.com> writes:
> Hello,
>
> I calculated
> (* 12 2.6) with the built in command CTRL + J and got
> 31.200000000000003
Hello, you have to use round like that:
,----
| ELISP> (/ (round (* 100
| (* 2.6 12)))
| 100.0)
| 31.2
`----
> It is the same for
> (* 2.6 12)
>
> I am wondering about the tailing numbers after 31.2!
>
> If I calculate (* 2.5 12) then the result is the expected 30.0.
>
> Can someone tell me the reason? Is there something wrong with
> my calcuation?
>
> I am using the official release:
>
> This is GNU Emacs 22.1.1 (i386-mingw-nt5.0.2195)
> of 2007-06-02 on RELEASE
>
> under Win2k.
>
> Thank you and kind regards
>
> Borde, Andreas
>
>
--
A + Thierry
Pub key: http://pgp.mit.edu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: calculation error with built-in command CTRL + J?!
2008-04-14 3:59 calculation error with built-in command CTRL + J?! Borde, Andreas
2008-04-14 6:11 ` David Hansen
2008-04-14 6:24 ` Thierry Volpiatto
@ 2008-04-14 6:40 ` Sven Joachim
2 siblings, 0 replies; 4+ messages in thread
From: Sven Joachim @ 2008-04-14 6:40 UTC (permalink / raw)
To: help-gnu-emacs
On 2008-04-14 05:59 +0200, Andreas Borde wrote:
> I calculated
> (* 12 2.6) with the built in command CTRL + J and got
> 31.200000000000003
A normal rounding error for floating point numbers.
> It is the same for
> (* 2.6 12)
Multiplication is commutative. ;-)
> I am wondering about the tailing numbers after 31.2!
The computer can only represent real numbers that are a linear
combination of (possibly negative) powers of 2, all other numbers can
only be approximated. See http://en.wikipedia.org/wiki/Floating_point
for details.
> If I calculate (* 2.5 12) then the result is the expected 30.0.
Because 2.5 = 2^1 + 2^(-1), therefore the computer can calculate exactly.
> Can someone tell me the reason? Is there something wrong with
> my calcuation?
No, there's nothing wrong. The following little C program prints the
same results as Emacs:
--8<---------------cut here---------------start------------->8---
#include <stdio.h>
int main(void)
{
printf("12 * 2.6 = %.15f\n", 12 * 2.6);
return 0;
}
--8<---------------cut here---------------end--------------->8---
Regards,
Sven
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-04-14 6:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-14 3:59 calculation error with built-in command CTRL + J?! Borde, Andreas
2008-04-14 6:11 ` David Hansen
2008-04-14 6:24 ` Thierry Volpiatto
2008-04-14 6:40 ` Sven Joachim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).