[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2] pkl,std: add `stof' and `stod'
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH v2] pkl,std: add `stof' and `stod' |
Date: |
Tue, 21 Mar 2023 23:02:32 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> Hi Jose.
>
> On Tue, Mar 21, 2023 at 10:44:25PM +0100, Jose E. Marchesi wrote:
>>
>> > +
>> > +/* 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?
>
> You mean something like this?
>
> ```poke
> raise Exception {
> code = EC_conv,
> name = "conversion error",
> msg = format ("string '%s' is not a valid floating-point number", s),
> exit_status = 1,
> };
> ```
>
> Example:
>
> ```
> (poke) stod ("H")
> unhandled conversion error exception
> string 'H' is not a valid floating-point number
> ```
Yeah.
- set floating point, Philippe Marchesseault, 2023/03/11
- Re: set floating point, Mohammad-Reza Nabipoor, 2023/03/13
- [PATCH] pkl,std: add `stof' and `stod', Mohammad-Reza Nabipoor, 2023/03/16
- Re: [PATCH] pkl,std: add `stof' and `stod', Jose E. Marchesi, 2023/03/16
- [PATCH v2] pkl,std: add `stof' and `stod', Mohammad-Reza Nabipoor, 2023/03/21
- Re: [PATCH v2] pkl,std: add `stof' and `stod', Jose E. Marchesi, 2023/03/21
- Re: [PATCH v2] pkl,std: add `stof' and `stod', Mohammad-Reza Nabipoor, 2023/03/21
- Re: [PATCH v2] pkl,std: add `stof' and `stod',
Jose E. Marchesi <=
- [PATCH v3] pkl,std: add `stof' and `stod', Mohammad-Reza Nabipoor, 2023/03/21
- Re: [PATCH v3] pkl,std: add `stof' and `stod', Jose E. Marchesi, 2023/03/21
- Re: [PATCH v3] pkl,std: add `stof' and `stod', Mohammad-Reza Nabipoor, 2023/03/22