* Can somebody help to explain why result from atan does not equal a real?
@ 2013-01-31 10:50 Hengqing Hu
2013-01-31 13:32 ` Noah Lavine
2013-01-31 23:51 ` Mark H Weaver
0 siblings, 2 replies; 7+ messages in thread
From: Hengqing Hu @ 2013-01-31 10:50 UTC (permalink / raw)
To: guile-user
Dear list,
The following behavior is observed on both guile 1.8 and guile 2.0.
Is it correct?
Can somebody elaborate why it happens?
guile> (atan 0 -1)
3.14159265358979
guile> (= 3.14159265358979 3.14159265358979)
#t
guile> (= (atan 0 -1) 3.14159265358979)
#f
--
Best Regards, Hengqing Hu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can somebody help to explain why result from atan does not equal a real?
2013-01-31 10:50 Can somebody help to explain why result from atan does not equal a real? Hengqing Hu
@ 2013-01-31 13:32 ` Noah Lavine
2013-01-31 14:50 ` John Darrington
2013-01-31 23:51 ` Mark H Weaver
1 sibling, 1 reply; 7+ messages in thread
From: Noah Lavine @ 2013-01-31 13:32 UTC (permalink / raw)
To: Hengqing Hu; +Cc: Guile Mailing List
[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]
What you have here is a precision problem.
When a floating-point number like pi is printed, I don't think you can
guarantee that the string representation will be read in the same way it
was read out. So when guile reads "3.14159265358979", it gives you some
floating point number that is *close to* what (atan 0 -1) returns, but not
necessarily the same.
That's why line 2 in your example returned #t - because both things were
read as the same number - but #f for line 3 - because (atan 0 -1) returns
something slightly different. You can see this in Guile 2.0:
scheme@(guile-user)> (atan 0 -1)
$7 = 3.14159265358979
scheme@(guile-user)> (= 3.14159265358979 (atan 0 -1))
$8 = #f
scheme@(guile-user)> (= $7 (atan 0 -1))
$9 = #t
It might be possible to have Guile print more digits and make this problem
go away.
Noah Lavine
On Thu, Jan 31, 2013 at 5:50 AM, Hengqing Hu <hengqing.hu@gmail.com> wrote:
> Dear list,
>
> The following behavior is observed on both guile 1.8 and guile 2.0.
> Is it correct?
> Can somebody elaborate why it happens?
>
> guile> (atan 0 -1)
> 3.14159265358979
> guile> (= 3.14159265358979 3.14159265358979)
> #t
> guile> (= (atan 0 -1) 3.14159265358979)
> #f
>
> --
> Best Regards, Hengqing Hu
>
>
[-- Attachment #2: Type: text/html, Size: 2474 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can somebody help to explain why result from atan does not equal a real?
2013-01-31 10:50 Can somebody help to explain why result from atan does not equal a real? Hengqing Hu
2013-01-31 13:32 ` Noah Lavine
@ 2013-01-31 23:51 ` Mark H Weaver
2013-02-01 0:30 ` Mark H Weaver
1 sibling, 1 reply; 7+ messages in thread
From: Mark H Weaver @ 2013-01-31 23:51 UTC (permalink / raw)
To: Hengqing Hu; +Cc: guile-user
Hengqing Hu <hengqing.hu@gmail.com> writes:
> The following behavior is observed on both guile 1.8 and guile 2.0.
> Is it correct?
> Can somebody elaborate why it happens?
>
> guile> (atan 0 -1)
> 3.14159265358979
> guile> (= 3.14159265358979 3.14159265358979)
> #t
> guile> (= (atan 0 -1) 3.14159265358979)
> #f
Sorry, this is due to an inadequate 'number->string' implementation in
Guile. A proper implementation should guarantee that when the string is
read back in, you'll get precisely the same number back, and recent
Scheme standards mandate this. At present, Guile does not always print
enough digits to guarantee this.
I plan to soon rewrite Guile's 'number->string' based on "Printing
Floating-Point Numbers Quickly and Accurately" by Dybvig and Burger.
I recently started that work but became distracted by more pressing
matters. I hope to get back to it soon.
Regards,
Mark
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-02-01 9:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-31 10:50 Can somebody help to explain why result from atan does not equal a real? Hengqing Hu
2013-01-31 13:32 ` Noah Lavine
2013-01-31 14:50 ` John Darrington
2013-01-31 14:52 ` Noah Lavine
2013-01-31 23:51 ` Mark H Weaver
2013-02-01 0:30 ` Mark H Weaver
2013-02-01 9:10 ` Mark H Weaver
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).