Page 1 of 1

Bug in (int)

Posted: Wed Nov 02, 2005 12:21 am
by zool
Consider the following:

(int "07") => 7

(int "08") => 0

Is this intentional?

/Christer

Posted: Wed Nov 02, 2005 12:30 am
by Sammo
Hello Christer,

It is intentional! Unless told otherwise (see manual), 'int' understands that number strings beginnning with numeral "0" (zero) are octal numbers. Since "08" is not a valid octal number, 'int' stops parsing the octal string at "0" and returns zero as the result.

The manual gives complete details and explains the optional parameters to 'int' to extract the result you might be expecting.

-- Sam

Posted: Wed Nov 02, 2005 2:34 am
by Lutz
yes, and 0 (zero) as an indicator for octal numbers is a common thing in programming languages, 'C", Perl and Python do similar, try:

Code: Select all

~> echo "print 077" | perl
63

~> echo "print 077" | python
63
the above executed in a unix/bash shell on Mac OSX

Lutz

Posted: Wed Nov 02, 2005 9:22 pm
by Dmi
I've lost one evening a month ago trying to debug similar problem ;-)
something like this will help:

Code: Select all

(define (int10 i) (int i 0 10))