is this a bug?

Started by tomtoo, August 03, 2013, 07:01:52 AM

Previous topic - Next topic

tomtoo


> (set 'a "0821")
"0821"
> (int a)
0


shouldn't this return 0821?



> (integer? 0821)
true

cormullion

#1
Not really - at least, not in newLISP... You didn't specify a number base, and then you announced an octal number with the initial "0". But then you blew it with the "8", which is not a valid octal digit. Also, you didn't specify a default value in the event of a failed conversion, so you got the default default, which is 0.



Try:


(int a 0 10)

jopython

#2
I will sanitise the input before conversion

(int (trim "0034234230" "0" ""))
=> 34234230

Lutz

#3
also consider speed:


> (time (int "0821" 0 10) 1000000)
95.273
> (time (int (trim "0821" "0" "")) 1000000)
530.1
>