unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#69725: Incorrect comapration between exact and inexact numbers
@ 2024-03-11  7:46 Maciej
  2024-03-18 16:17 ` lloda
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej @ 2024-03-11  7:46 UTC (permalink / raw)
  To: 69725


description:

script(named main.scm):
(use-modules (srfi srfi-11))

(define* (newton-sqrt x #:optional (tolerance 0.001) (guess 1))
  (if (< (abs (- x (* guess guess)))
	 tolerance)
      (values guess (abs (- x (* guess guess))) tolerance)
      (newton-sqrt x tolerance (/ (+ guess (/ x guess)) 2))))

(let-values ([(root diff tolerance)
	      (newton-sqrt 1000)])
  (display (exact->inexact diff)) ;; 1.217168231948292
  (newline)
  (display tolerance) ;; 0.001
  (newline)
  ;; bug here 1.217 in exact form apparently is smaller than 0.001
  (display (< diff tolerance)) ;; #t
  (newline)
  (display (< diff (inexact->exact tolerance))) ;; #f
  (newline)
  (display (< (exact->inexact diff) tolerance)) ;; #f
  (newline))

guile version:
guile --version
guile (GNU Guile) 3.0.9

machine-type:
./config.guess
x86_64-pc-linux-gnu

system package:
guix package -V guile
guix package (GNU Guix) f18d13b5f89c161c6ee88d15ecdaa8d973ee4503

additional system info:
guix channels.scm
(list (channel
        (name 'guix)
        (url "https://git.savannah.gnu.org/git/guix.git")
        (branch "master")
        (commit
          "aeb494322ca9dec4a4d66a7d063239c8536bd538")
        (introduction
          (make-channel-introduction
            "9edb3f66fd807b096b48283debdcddccfea34bad"
            (openpgp-fingerprint
              "BBB0 2DDF 2CEA F6A8 0D1D  E643 A2A0 6DF2 A33A 54FA")))))

what i ran to run the script:
guix time-machine -C channels.scm -- shell --pure guile -- ./main.scm
1.217168231948292
0.001
#t
#f
#f





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

end of thread, other threads:[~2024-03-19 17:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-11  7:46 bug#69725: Incorrect comapration between exact and inexact numbers Maciej
2024-03-18 16:17 ` lloda
2024-03-19 17:29   ` lloda

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).