Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/zenans.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH library - ZEN FP ANS layer - Copyright 2009 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] fdup [IF]
[UNDEFINED] f+   [IF] [ABORT] [THEN]
[UNDEFINED] 2@   [IF] include lib/anscore.4th  [THEN]
aka 2rot  frot                         \ simple synonyms
aka 2over fover
aka 2@    f@
aka 2!    f!

2 cells constant float

: float+ cell+ cell+ ;
: floats float * ;

: fdup  2dup  ;                        \ equivalents of double stack words
: fswap 2swap ;
: fdrop 2drop ;

[UNDEFINED] >float [IF]                \ ONLY supports "e", no decimal point
: >float                               ( a n -- f bool)
  2dup bounds                          \ set up loop, scan for "e"
  begin dup c@ bl or [char] e <> while over over <> while char+ repeat nip
  >r over r@ swap - tuck 1+ - r> char+ \ construct strings and convert
  swap dup 0> if number else drop dup xor then
  >r number error? r> error? rot or dup if nip nip then 0= 
;                                      \ return numbers and flag
                                       ( a n -- f)
: s>float >float 0= abort" Bad float" ;
[THEN]
[THEN]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.