* bug#29387: Guile-2.2.2 complex numbers edge case
@ 2017-11-21 22:09 Jan Wedekind
0 siblings, 0 replies; 4+ messages in thread
From: Jan Wedekind @ 2017-11-21 22:09 UTC (permalink / raw)
To: 29387
Hi,
I think I encountered a bug in the numerical stack.
i times i should equal -1:
(equal? -1 (* 0+i 0+i))
; #f
i times i plus one is zero (which is correct):
(zero? (+ (* 0+i 0+i) 1))
; #t
Regards
Jan
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#29387: Guile-2.2.2 complex numbers edge case
[not found] <mailman.9100.1511364130.27994.bug-guile@gnu.org>
@ 2017-11-22 15:53 ` Daniel Llorens
2017-11-22 18:32 ` Jan Wedekind
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Llorens @ 2017-11-22 15:53 UTC (permalink / raw)
To: 29387; +Cc: jan
[-- Attachment #1: Type: text/plain, Size: 960 bytes --]
> From: Jan Wedekind <jan@wedesoft.de>
> Subject: bug#29387: Guile-2.2.2 complex numbers edge case
> Date: 21 Nov 2017 23:09:57 GMT+1
> To: 29387@debbugs.gnu.org
> Reply-To: Jan Wedekind <jan@wedesoft.de>
>
>
> Hi,
> I think I encountered a bug in the numerical stack.
> i times i should equal -1:
>
> (equal? -1 (* 0+i 0+i))
> ; #f
>
> i times i plus one is zero (which is correct):
> (zero? (+ (* 0+i 0+i) 1))
> ; #t
>
> Regards
> Jan
In Guile 0+i and (* 0+i 0+i) are inexact numbers, but -1 is exact. That's why equal? fails.
You can check that either of
(equal? -1.+0. (* 0+i 0+i))
or
(= -1 (* 0+i 0+i))
return true, as expected.
I don't know if the fact that Guile doesn't have exact complex numbers could be considered a bug. AFAIR none of the standards require them to be implemented. On the other hand I just checked and both Racket and Chez seem to have them, so...
regards
Daniel
[-- Attachment #2: Type: text/html, Size: 2800 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#29387: Guile-2.2.2 complex numbers edge case
2017-11-22 15:53 ` Daniel Llorens
@ 2017-11-22 18:32 ` Jan Wedekind
[not found] ` <FE47AB49-84AF-494F-9AEA-160AB09FB4FF@bluewin.ch>
0 siblings, 1 reply; 4+ messages in thread
From: Jan Wedekind @ 2017-11-22 18:32 UTC (permalink / raw)
To: Daniel Llorens, 29387
[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]
Thanks Daniel,
I see. So I need to use "=" for numerical comparisons. "equal?" is only true if the types are the same, too:
(equal? 1.0 1)
; #f
(= 1.0 1)
; #t
Sorry for filing a bug report. Feel free to close the bug.
Regards
Jan
On November 22, 2017 3:53:00 PM GMT, Daniel Llorens <daniel.llorens@bluewin.ch> wrote:
>
>> From: Jan Wedekind <jan@wedesoft.de>
>> Subject: bug#29387: Guile-2.2.2 complex numbers edge case
>> Date: 21 Nov 2017 23:09:57 GMT+1
>> To: 29387@debbugs.gnu.org
>> Reply-To: Jan Wedekind <jan@wedesoft.de>
>>
>>
>> Hi,
>> I think I encountered a bug in the numerical stack.
>> i times i should equal -1:
>>
>> (equal? -1 (* 0+i 0+i))
>> ; #f
>>
>> i times i plus one is zero (which is correct):
>> (zero? (+ (* 0+i 0+i) 1))
>> ; #t
>>
>> Regards
>> Jan
>
>In Guile 0+i and (* 0+i 0+i) are inexact numbers, but -1 is exact.
>That's why equal? fails.
>
>You can check that either of
>
>(equal? -1.+0. (* 0+i 0+i))
>
>or
>
> (= -1 (* 0+i 0+i))
>
>return true, as expected.
>
>I don't know if the fact that Guile doesn't have exact complex numbers
>could be considered a bug. AFAIR none of the standards require them to
>be implemented. On the other hand I just checked and both Racket and
>Chez seem to have them, so...
>
>regards
>
> Daniel
[-- Attachment #2: Type: text/html, Size: 3454 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#29387: Guile-2.2.2 complex numbers edge case
[not found] ` <FE47AB49-84AF-494F-9AEA-160AB09FB4FF@bluewin.ch>
@ 2017-11-23 14:48 ` Daniel Llorens
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Llorens @ 2017-11-23 14:48 UTC (permalink / raw)
To: Jan Wedekind; +Cc: 29387-close
On 22 Nov 2017, at 19:32, Jan Wedekind <jan@wedesoft.de> wrote:
> Thanks Daniel,
> I see. So I need to use "=" for numerical comparisons. "equal?" is only true if the types are the same, too:
>
> (equal? 1.0 1)
> ; #f
> (= 1.0 1)
> ; #t
>
> Sorry for filing a bug report. Feel free to close the bug.
no problem! closing the bug (right this time)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-23 14:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-21 22:09 bug#29387: Guile-2.2.2 complex numbers edge case Jan Wedekind
[not found] <mailman.9100.1511364130.27994.bug-guile@gnu.org>
2017-11-22 15:53 ` Daniel Llorens
2017-11-22 18:32 ` Jan Wedekind
[not found] ` <FE47AB49-84AF-494F-9AEA-160AB09FB4FF@bluewin.ch>
2017-11-23 14:48 ` Daniel Llorens
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).