Got hex floats working

This commit is contained in:
iko 2024-05-17 15:07:35 +03:00
parent 1bea1efb8f
commit 381302386b
Signed by untrusted user: iko
GPG Key ID: 82C257048D1026F2
2 changed files with 51 additions and 2 deletions

View File

@ -319,7 +319,10 @@
;~ pose
%+ cook
|= x=@rd [%float x]
parse-float
;~ pose
parse-float
parse-hex-float
==
::
%+ cook
|= x=@u [%int x]
@ -585,6 +588,52 @@
==
==
==
++ parse-hex-float
%+ knee *@rd
|.
=<
%+ sear
|= [* * int=tape frac=(unit tape) exp=(unit [exp-sign=? exp=@])]
?: ?=([~ ~] [frac exp]) ~
%- some
=/ frac (fall frac "")
=/ whole=@rd (sun:rd (scan (weld int frac) hex))
=/ frac-exp=@rd (sun:rd (pow 16 (lent frac)))
=/ without-exp (div:rd whole frac-exp)
?~ exp without-exp
=/ exp-exp (sun:rd (pow 2 exp.u.exp))
?: exp-sign.u.exp
(mul:rd without-exp exp-exp)
(div:rd without-exp exp-exp)
;~ plug
(just '0')
::
(mask "xX")
::
(plus hex-digit)
::
%- punt
;~ pfix
dot
(plus hex-digit)
==
::
%- punt
;~ pfix
(mask "pP")
;~(plug ;~(pose (cold | hep) (cold & lus) (easy &)) dim:ag)
==
==
|%
++ hex-digit
%+ knee *char
|.
;~ pose
(shim '0' '9')
(shim 'a' 'f')
(shim 'A' 'F')
==
--
++ show-float
|= x=@rd
^- tape

View File

@ -40,5 +40,5 @@ test_cases = {
foo = {
3.0, 3.1416, 314.16e-2, 0.31416E1, 34e1,
0x0.1E, 0xA23p-4, 0X1.921FB54442D18P+1
0x0.1E, 0xA23p-4, 0xA23p-4, 0X1.921FB54442D18P+1, 0x1.fp10
}