Re: Should to_number return a sequence?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Phix is a bit different: to_number(s,failure={},inbase=10) is in fact a mini-wrapper to scanf() [see below] and never returns a bad_pos.
There is a separate and simpler to_integer(s,def_value=0,base=10) and an is_integer(s,base=10) to go with that.
scanf(s,fmt) tries to reconstitute p such that sprintf(fmt,p) would have produced s, and collects all p it can think of before trimming
that set down to those that match exactly, as long as that does not get rid of all of them. [Not very relevant to to_number, that part.]

xecronix said...

I added a is_number function to my wiki. It might be useful to someone. https://openeuphoria.org/wiki/view/Is%20Number%20Function.wc

Your is_number("-") crashes.

I'll also suggest:

    and (i + 1 > length(maybe)) then  

==>

    and i = length(maybe) then  

and

    while i < (length(maybe) + 1) do  

==>

    while i <= length(maybe) do  

and

 
        if equal(c, '.') and found_dot then  
            return 0  
        end if  
  
        if equal(c, '.') then   
            found_dot = 1  

==>

 
        if equal(c, '.') then   
            if found_dot then return 0 end if  
            found_dot = 1  
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu