Page 1 of 1

is this a bug?

Posted: Sat Aug 03, 2013 2:01 pm
by tomtoo

Code: Select all

> (set 'a "0821")
"0821"
> (int a)
0
shouldn't this return 0821?

Code: Select all

> (integer? 0821)
true

Re: is this a bug?

Posted: Sat Aug 03, 2013 3:24 pm
by cormullion
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:

Code: Select all

(int a 0 10)

Re: is this a bug?

Posted: Sat Aug 03, 2013 4:13 pm
by jopython
I will sanitise the input before conversion

Code: Select all

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

Re: is this a bug?

Posted: Sat Aug 03, 2013 7:58 pm
by Lutz
also consider speed:

Code: Select all

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