From: Noah Lavine <noah.b.lavine@gmail.com>
To: Hengqing Hu <hengqing.hu@gmail.com>
Cc: Guile Mailing List <guile-user@gnu.org>
Subject: Re: Can somebody help to explain why result from atan does not equal a real?
Date: Thu, 31 Jan 2013 08:32:53 -0500 [thread overview]
Message-ID: <CA+U71=MEU3sU_RZKqXW8xjKdtHX=HxMWsm-8UXb-qUcHeCgMeQ@mail.gmail.com> (raw)
In-Reply-To: <CADFbkvB-xhoNw2b8ubZecKoc4VmiC_dycVjZA3p3KHEGhaHbmg@mail.gmail.com>
[-- 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 --]
next prev parent reply other threads:[~2013-01-31 13:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+U71=MEU3sU_RZKqXW8xjKdtHX=HxMWsm-8UXb-qUcHeCgMeQ@mail.gmail.com' \
--to=noah.b.lavine@gmail.com \
--cc=guile-user@gnu.org \
--cc=hengqing.hu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).