stringtofloat.txt


\ string>float 00.3.17 10:02 am NAB
needs string

: string>float ( c-addr u -- ) ( F: -- r )
  -trailing
  0 >r  \ negative flag, false to start
  begin
\ Attempt float conversion:
    2dup >float 0= while  \ failed
\ If string is empty, return 0E:
      dup
      0= if  2drop 0e  r> drop exit then
\ If first char is '-', update flag:
      over c@
      dup [char] - = if  r> drop >r
      else  drop  then
      1 /string
  repeat
  2drop  r>  if  fnegate  then ;


  HTMLized by Forth2HTML