|
From: | Jose E. Marchesi |
Subject: | Re: [PATCH v2] pkl,std: add `stof' and `stod' |
Date: | Tue, 21 Mar 2023 22:44:25 +0100 |
User-agent: | Gnus/5.13 (Gnus v5.13) |
Hi Mohammad. Thanks for the patch. > + > +/* String conversion to 32-bit floating-point number represented > + as `uint<32>'. */ > + > +fun stof = (string s) uint<32>: > +{ > + var f = asm any: ("stof" : s); > + > + if (asm int<32>: ("nn; nip" : f)) > + return f as uint<32>; > + raise E_conv; > +} > + > +/* String conversion to 64-bit floating-point number represented > + as `uint<64>'. */ > + > +fun stod = (string s) uint<64>: > +{ > + var d = asm any: ("stod" : s); > + > + if (asm int<32>: ("nn; nip" : d)) > + return d as uint<64>; > + raise E_conv; > +} What about adding an explicative message to the raised exceptions?
[Prev in Thread] | Current Thread | [Next in Thread] |