Opened 15 years ago

Closed 15 years ago

#206 closed defect (fixed)

number->string in numbers egg does not fail correctly

Reported by: Christian Kellermann Owned by: sjamaan
Priority: minor Milestone:
Component: extensions Version:
Keywords: numbers Cc: sjamaan
Estimated difficulty:

Description

(number->string "7") -> #f
(use numbers)
(number->string "7" 3) -> 7

I will try to come up with a patch.

Change History (6)

comment:1 Changed 15 years ago by felix winkelmann

Cc: sjamaan added
Milestone: 4.5.0

comment:2 in reply to:  description Changed 15 years ago by Christian Kellermann

Replying to ckeen:

(number->string "7") -> #f
(use numbers)
(number->string "7" 3) -> 7

This of course is nonsense! Sorry for adding to the confusion.

The correct and still failing case is
(string->number)

comment:3 Changed 15 years ago by Christian Kellermann

When calling the core version base should be passed to it too:

Index: numbers.scm
===================================================================
--- numbers.scm (revision 17731)
+++ numbers.scm (working copy)
@@ -1670,7 +1670,7 @@

(if (and m (pair? (cdr m)) (pair? (cadr m)))

(fin (make-complex 0 (real sub (caadr m) (cadadr m))))
(fin (or (real str start len)

  • (string->number-0 str) )) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )

+ (string->number-0 str base) )) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )

comment:4 Changed 15 years ago by Christian Kellermann

And here is a test case for it:
Index: numbers-test.scm
===================================================================
--- numbers-test.scm (revision 17731)
+++ numbers-test.scm (working copy)
@@ -447,6 +447,7 @@

(test "fix" 123 (string->number "123"))
(test "fix/base" 255 (string->number "ff" 16))
(test "fix/base-o" 14 (string->number "16" 8))

+ (test "fix/wrong-base" #f (string->number "123" 3))

(test "flo" 0.0 (string->number "#"))
(test "flo" 123.23 (string->number "123.23"))
(test "flo2" 100.23 (string->number "1##.23"))

comment:5 Changed 15 years ago by sjamaan

Owner: set to sjamaan
Status: newaccepted

Patches are applied (with a small change in the tests)

Thank you!

Please close the ticket if this is alright by you.

comment:6 Changed 15 years ago by Christian Kellermann

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.