<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>A library that implements IEEE-754:  <a class="moz-txt-link-freetext" href="http://speleotrove.com/decimal/">http://speleotrove.com/decimal/</a>
    </p>
    <p>Example implementations in Erlang:<br>
    </p>
    <p><a class="moz-txt-link-freetext" href="https://github.com/tim/erlang-decimal">https://github.com/tim/erlang-decimal</a><br>
    </p>
    <p><a class="moz-txt-link-freetext" href="https://github.com/egobrain/decimal">https://github.com/egobrain/decimal</a></p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 3/17/19 1:29 AM, Richard O'Keefe
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CABcYAdJzRFC5i7exXXtV-BwV7hUL2S3j06FnKao8=EruS4jAhg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div class="gmail_default"
          style="font-family:monospace,monospace">What do you mean by "a
          decimal lib"?<br>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Sun, 17 Mar 2019 at 06:35,
          Bryan Paxton <<a href="mailto:starbelly@pobox.com"
            moz-do-not-send="true">starbelly@pobox.com</a>> wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div bgcolor="#FFFFFF">
            <p> All of this begs the question of why there is no decimal
              lib in otp... I'm sure there's a good reason... ?</p>
            <p><br>
            </p>
            <div class="gmail-m_555742592463524003moz-cite-prefix">On
              3/16/19 12:31 PM, Bob Ippolito wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">While it's more code, the most
                straightforward way would be to parse the whole float
                for that spec into its constituent parts and reassemble
                (with defaults where necessary) to parse with
                float_to_list.
                <div><br>
                </div>
                <div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Sat, Mar 16, 2019
                  at 4:32 AM Hugo Mills <<a
                    href="mailto:hugo@carfax.org.uk" target="_blank"
                    moz-do-not-send="true">hugo@carfax.org.uk</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">   Hi, Bob,<br>
                  <br>
                  On Fri, Mar 15, 2019 at 05:32:54PM -0700, Bob Ippolito
                  wrote:<br>
                  > If you dive into the implementation it's
                  effectively a wrapper around<br>
                  > strtod from C with a validation pass that is more
                  strict than the strtod<br>
                  > standard.<br>
                  > <br>
                  > <a
href="https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/win32/sys_float.c#L54"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/win32/sys_float.c#L54</a><br>
                  > <a
href="https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/unix/sys_float.c#L732"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">https://github.com/erlang/otp/blob/OTP-21.3/erts/emulator/sys/unix/sys_float.c#L732</a><br>
                  > <br>
                  > So as far as a regex goes it would be something
                  like this:<br>
                  > <br>
                  > [+-]?\d+[.,]\d+([eE][+-]?\d+)<br>
                  > <br>
                  > The major differences between this and other
                  popular float grammars are:<br>
                  > <br>
                  > * At least one digit is required in each part<br>
                  > * Both integer and fractional parts are required,
                  even if there's an<br>
                  > exponent part (so "1", ".1", "1e-1" would not be
                  valid)<br>
                  > * The decimal separator is either , or . (the
                  implementation will try the<br>
                  > other if necessary to compensate for a different
                  locale)<br>
                  <br>
                     Thanks for the confirmation. That's more or less
                  what I discovered<br>
                  while playing around with list_to_float. It's the
                  first two cases that<br>
                  are the problems for me, because the spec I'm working
                  to(*) says that<br>
                  "1." and ".3" are valid floats, for example, as is
                  "1e-1".<br>
                  <br>
                     Just for the record, here's the code I'm using to
                  convert a Turtle<br>
                  double or decimal (the former in scientific notation;
                  the latter<br>
                  without the E) into a form suitable for
                  list_to_float/1:<br>
                  <br>
                      [...]<br>
                      % W3C's description of a float is wider than
                  erlang's. We need to<br>
                      % split up the number into a few parts to add
                  extra characters<br>
                      % where necessary so that list_to_float/1 will
                  work right.<br>
                      F = case string:lexemes(Text, "eE") of<br>
                          [M, E] -><br>
                              fixup_decimal(M) ++ "e" ++ E;<br>
                          [M] -><br>
                              fixup_decimal(M)<br>
                      end,<br>
                      O = lagra_model:new_literal(list_to_float(F)),<br>
                      [...]<br>
                  <br>
                  -spec fixup_decimal(string()) -> string().<br>
                  fixup_decimal(M) -><br>
                      case string:lexemes(M, ".") of<br>
                          [I] -><br>
                              I++".0";<br>
                          [I, ""] -><br>
                              I++".0";<br>
                          ["", J] -><br>
                              "0."++J;<br>
                          [I, J] -><br>
                              M<br>
                      end.<br>
                  <br>
                     Hugo.<br>
                  <br>
                  (*) W3C's Turtle recommendation.<br>
                  <br>
                  <br>
                  > On Fri, Mar 15, 2019 at 3:52 PM Hugo Mills <<a
                    href="mailto:hugo@carfax.org.uk" target="_blank"
                    moz-do-not-send="true">hugo@carfax.org.uk</a>>
                  wrote:<br>
                  > <br>
                  > >    Where in the manual is the set of
                  allowable string representations<br>
                  > > of floating point numbers documented? I'd
                  have expected it to be here:<br>
                  > ><br>
                  > > <a
                    href="http://erlang.org/doc/reference_manual/data_types.html"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">http://erlang.org/doc/reference_manual/data_types.html</a><br>
                  > ><br>
                  > > ... but apparently not.<br>
                  > ><br>
                  > >    Specifically, I'm trying to use
                  list_to_float/1, and I've been<br>
                  > > trying to reverse engineer it:<br>
                  > ><br>
                  > > 1> list_to_float("-1").<br>
                  > > ** exception error: bad argument<br>
                  > >      in function  list_to_float/1<br>
                  > >         called as list_to_float("-1")<br>
                  > > 2> list_to_float("-1.0").<br>
                  > > -1.0<br>
                  > > 3> list_to_float("-1.0e-23").<br>
                  > > -1.0e-23<br>
                  > > 4> list_to_float("-1e-23").<br>
                  > > ** exception error: bad argument<br>
                  > >      in function  list_to_float/1<br>
                  > >         called as list_to_float("-1e-23")<br>
                  > > 5> list_to_float(".3").<br>
                  > > ** exception error: bad argument<br>
                  > >      in function  list_to_float/1<br>
                  > >         called as list_to_float(".3")<br>
                  > ><br>
                  > >    An actual written specification would be
                  really handy here. Even<br>
                  > > just a regex or EBNF for them. I'm writing a
                  parser for something<br>
                  > > where the definition of floating point
                  literals isn't quite the same<br>
                  > > as Erlang's, and it's a bit painful.<br>
                  > ><br>
                  > >    Hugo.<br>
                  > ><br>
                  <br>
                  -- <br>
                  Hugo Mills             | Nostalgia isn't what it used
                  to be.<br>
                  hugo@... <a href="http://carfax.org.uk"
                    rel="noreferrer" target="_blank"
                    moz-do-not-send="true">carfax.org.uk</a> |<br>
                  <a href="http://carfax.org.uk/" rel="noreferrer"
                    target="_blank" moz-do-not-send="true">http://carfax.org.uk/</a> 
                  |<br>
                  PGP: E2AB1DE4          |<br>
                  -----BEGIN PGP SIGNATURE-----<br>
                  Version: GnuPG v1.4.12 (GNU/Linux)<br>
                  <br>
iQIcBAEBAgAGBQJcjN62AAoJEFheFHXiqx3kiPAP/3V2SC+mFVSIjRw0moQC6keJ<br>
x8A+005H7+SO030G5/a0TYXEe9wxn1KEtQEEyG2yt6A1XASeERRFuAPeeFMEhti+<br>
trr1oYJmbSTUgvRs1i5jhSH7KmUEt09I+JgS3u0Xs92LkmNyfFde8K3z6uA1XKwp<br>
7tIHihrXYpk/jMamWXTNGYPlHtxcVxAToNK8ajQTz6dElurZYdHwHtnFv7Ya7jcf<br>
7w9fKG4XcIoQZHMBrnZF8g2UQIgWiMpz7eo5lko91Zbjetgv1qkKaiNonA+rai4b<br>
CVIXJ+YIT1dHNEQ76uVqJQuuklUB0M5B+FCX/zuS5Zd7mta9ljzBHefGLzQYT+EE<br>
Y4En5n+YvL5OUCqw0EBBXBTYcsdn8rP0+jSy3nFiX6zV4Ty49NrKCSN0LGQJVpkz<br>
wv1Sl05QBC2JcyCYqrCoMdudPNdcgK/TvB+H7KYcZDy3mgoZJ55U12Ys6Ng80tIa<br>
3eUis3W4vZLdS9Gfn8GY4A42APvv6X3W9bVN5JEISUlF3CdKui/RItZiQ8whx4iF<br>
6E+KzkO6AgmgyGKbAXK5N8S0MWuNT3g/V/tm7siY3GDG6cDIQNZRxevMXhAZ9nIv<br>
S3kAiz1JBUKIMWv3RCz77+gKPI7AiUBHlfmXsjudSbnJ9r6nxhbCjbbypmHOzZYx<br>
                  5uMAhklJZ0OnQgmxOfVU<br>
                  =0Eaq<br>
                  -----END PGP SIGNATURE-----<br>
                </blockquote>
              </div>
              <br>
              <fieldset
                class="gmail-m_555742592463524003mimeAttachmentHeader"></fieldset>
              <pre class="gmail-m_555742592463524003moz-quote-pre">_______________________________________________
erlang-questions mailing list
<a class="gmail-m_555742592463524003moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org" target="_blank" moz-do-not-send="true">erlang-questions@erlang.org</a>
<a class="gmail-m_555742592463524003moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank" moz-do-not-send="true">http://erlang.org/mailman/listinfo/erlang-questions</a></pre>
            </blockquote>
            <p><br>
            </p>
            <p>--</p>
            <p>Bryan Paxton<br>
            </p>
            <blockquote type="cite"> </blockquote>
          </div>
          _______________________________________________<br>
          erlang-questions mailing list<br>
          <a href="mailto:erlang-questions@erlang.org" target="_blank"
            moz-do-not-send="true">erlang-questions@erlang.org</a><br>
          <a href="http://erlang.org/mailman/listinfo/erlang-questions"
            rel="noreferrer" target="_blank" moz-do-not-send="true">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>