unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#14905: rationalize not returning the simplest rational
@ 2013-07-19 11:18 Göran Weinholt
  2013-07-21 10:56 ` Mark H Weaver
  0 siblings, 1 reply; 2+ messages in thread
From: Göran Weinholt @ 2013-07-19 11:18 UTC (permalink / raw)
  To: 14905

[-- Attachment #1: Type: text/plain, Size: 762 bytes --]

Hello schemers,

the procedure (rationalize x1 x2) from (rnrs) takes a number x1 and
returns the simplest rational that doesn't differ from x1 by more than
x2. The implementation in guile has this behavior:

scheme@(guile-user)> (rationalize #e-0.67 1/4)
$1 = -2/3

The problem here is that -1/2 is simpler than -2/3 (since 1<2 and 2<3)
and it also doesn't differ from #e-0.67 by more than 1/4 (even though
the difference is larger than for -2/3, it is still less than 1/4). So
the result from the expression above should be -1/2.

Tested with Guile 2.0.9.40-824b-dirty.

Regards,

-- 
Göran Weinholt <goran@weinholt.se>
"On your own and though you feel alone you are alive.
Don't you know it's just another day." -- You Are Alive, Fragma

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#14905: rationalize not returning the simplest rational
  2013-07-19 11:18 bug#14905: rationalize not returning the simplest rational Göran Weinholt
@ 2013-07-21 10:56 ` Mark H Weaver
  0 siblings, 0 replies; 2+ messages in thread
From: Mark H Weaver @ 2013-07-21 10:56 UTC (permalink / raw)
  To: Göran Weinholt; +Cc: 14905-done

Göran Weinholt <goran@weinholt.se> writes:

> the procedure (rationalize x1 x2) from (rnrs) takes a number x1 and
> returns the simplest rational that doesn't differ from x1 by more than
> x2. The implementation in guile has this behavior:
>
> scheme@(guile-user)> (rationalize #e-0.67 1/4)
> $1 = -2/3
>
> The problem here is that -1/2 is simpler than -2/3 (since 1<2 and 2<3)
> and it also doesn't differ from #e-0.67 by more than 1/4 (even though
> the difference is larger than for -2/3, it is still less than 1/4). So
> the result from the expression above should be -1/2.

Fixed in 620c13e8fc02060e0af8fa38398ee4de745d41e9.

    Thanks!
      Mark





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-07-21 10:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-19 11:18 bug#14905: rationalize not returning the simplest rational Göran Weinholt
2013-07-21 10:56 ` 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).