/hmsl/fth/float_port.fth

https://github.com/philburk/hmsl · Forth · 63 lines · 49 code · 14 blank · 0 comment · 0 complexity · 85475e93c93645f6214943fdb2f4311d MD5 · raw file

  1. \ Floating point words from HMSL redefined using ANSI Forth
  2. \
  3. \ Author: Phil Burk
  4. \ Copyright 2016 - Phil Burk, Larry Polansky, David Rosenboom.
  5. \ All Rights Reserved
  6. ANEW TASK-FLOAT_PORT
  7. : FPINIT ; \ not needed, floats always available
  8. : FPTERM ;
  9. : FMOD ( r1 r2 -f- rem{f1/f2} , calc remainder )
  10. fover fover f/
  11. f>s s>f
  12. f* f-
  13. ;
  14. : F= ( r1 r2 -f- , -- flag )
  15. f- f0=
  16. ;
  17. : F> ( r1 r2 -f- , -- flag )
  18. fswap f<
  19. ;
  20. : F>I ( r -f- , -- n )
  21. f>s
  22. ;
  23. : FIX ( r -f- , -- n , rounds )
  24. fround
  25. ;
  26. : FLOAT ( n -- , -f- r , convert to float )
  27. s>f
  28. ;
  29. : I>F ( n -- , -f- r , convert to float )
  30. s>f
  31. ;
  32. : INT ( r -f- , -- n )
  33. f>s
  34. ;
  35. : F>TEXT ( r -f- addr count , converts fp to text )
  36. (f.)
  37. ;
  38. : F.R ( r -f- , width -- , set width of field, print )
  39. >r \ save width
  40. (f.)
  41. r> over - spaces
  42. type
  43. ;
  44. : PLACES ( n -- , sets default number of fractional digits )
  45. set-precision \ this is not quite right, this sets significant digits
  46. ;
  47. : FNUMBER? ( $string -- true | false , -f- r )
  48. number? \ handles both ints and floats
  49. ;