Bug in (int)

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
zool
Posts: 4
Joined: Sat Jun 11, 2005 11:21 pm
Location: Linköping (during semesters), Sweden

Bug in (int)

Post by zool »

Consider the following:

(int "07") => 7

(int "08") => 0

Is this intentional?

/Christer

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Dmi
Posts: 408
Joined: Sat Jun 04, 2005 4:16 pm
Location: Russia
Contact:

Post 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))
WBR, Dmi

Locked