poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] pkl,std: add `stof' and `stod'


From: Mohammad-Reza Nabipoor
Subject: Re: [PATCH v2] pkl,std: add `stof' and `stod'
Date: Tue, 21 Mar 2023 22:52:44 +0100

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
```



reply via email to

[Prev in Thread] Current Thread [Next in Thread]