Bug in (int)

Started by zool, November 01, 2005, 04:21:47 PM

Previous topic - Next topic

zool

Consider the following:



(int "07") => 7



(int "08") => 0



Is this intentional?



/Christer

Sammo

#1
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

Lutz

#2
yes, and 0 (zero) as an indicator for octal numbers is a common thing in programming languages, 'C", Perl and Python do similar, try:



~> echo "print 077" | perl
63

~> echo "print 077" | python
63


the above executed in a unix/bash shell on Mac OSX



Lutz

Dmi

#3
I've lost one evening a month ago trying to debug similar problem ;-)

something like this will help:
(define (int10 i) (int i 0 10))
WBR, Dmi