Re: the BigDecimal g/G suffix?

MG <mgbiz-yvYIh6MZAuFWk0Htik3J/[email protected]> Thu, 21 Aug 2025 17:45:20 +0200
Newsgroups gmane.comp.lang.groovy.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------NF7hO1fUSrJe30YIqsbdWqn1
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi OC,

 1. not everyone that uses Groovy might be aware that a floting point
    number literal will automatically be a BD, so supporting g/G suffix
    makes total sense to let a user rest assured on what he will get.
 2. In addition, sometimes one wants to express in code that one is
    aware of something, in this case that a number literal is a BD,
    which again the suffix let's you express that.
 3. And finally, to me at least, supporting g/G even if it is
    syntactically speaking superfluous, is exactly what makes a language
    consistent.
 4. What I can see, is that one could want an option to directly express
    that a given integer literal shall be treated as a BD, without going
    through the rather ugly 1G.toBigDecimal()
     1. Which imho is also clearly worse than 1.0G .
     2. However, as this might lead to clashes with potential future
        Java suffixes I think it would be hard to come up with a good
        candidate (?)
         1. Which poses the question whether it would be worth the effort...

Cheers,
mg

Am 20.08.2025 um 04:39 schrieb OCsite:
> Thanks for the quick reply!
>
> Well primarily I don't get the point of the existence of the BD g/G 
> suffix at all. So that it works, the number before needs to contain . 
> or e; but if so, the number is a BD anyway even without the suffix. Is 
> there /any/ case where the g/G BD suffix wouldn't be completely 
> superfluous and adding/removing it would change the code behaviour in 
> the slightest?
>
> Aside of that, there is a /very minute/ and /completely unimportant/ 
> limitation that when I happen to need a BD constant whose value 
> happens to be integral (eg., 1 or 666), there is (far as I know) no 
> way to express it with a suffix in a format 1x, 666x (where x would be 
> the suffix). That's somewhat inconsistent with other cases, e.g., 1f, 
> 666f when the type I happen to need is a float.
>
> Nevertheless of course adding “.0” to get a BD is trivial and works 
> reliably, thus it's really just a question of consistency, nothing else :)
>
> Thanks and all the best,
> OC
>
>> On 20. 8. 2025, at 3:46, Paul King <[email protected]> wrote:
>>
>> 1g or 1G gives a BigInteger and here the suffix is required to not 
>> get an Integer. Using 1.0g/G for BD seems a natural extension.
>>
>> Most expressions involving both BI and BD give the results you'd 
>> expect so I believe it was thought at the time that using the same 
>> suffix was sufficient, with toBigInteger() and toBigDecimal() 
>> allowing you to swap between them if really needed.
>>
>> Do you have a particular scenario that you find that the current 
>> conventions limit you, or are you just noticing the trade-offs that 
>> were made in this case and making sure you fully understand them?
>>
>> Paul.
>>
>>
>> On Wed, Aug 20, 2025 at 2:13 AM OCsite <[email protected]> wrote:
>>
>>     Hi there,
>>
>>     I've just bumped into
>>     https://groovy-lang.org/syntax.html#_number_type_suffixes, namely, to
>>
>>     BigDecimal
>>
>>     	
>>
>>     |G| or |g|
>>
>>
>>     which seems rather pointless to me. When one enters a decimal
>>     number (e.g., 1.0), it's a BD anyway, suffix or not. On the other
>>     hand, there seems to be no suffix which would allow to write
>>     e.g., just 1s (s for /something/) creating a 1 BD, which would
>>     make some sense, like e.g., 1f for float does.
>>
>>     What do I overlook? What's the point of the BD g/G suffix, and
>>     why there's no suffix which would work without a decimal point
>>     (or exponent)?
>>
>>     Thanks,
>>     OC
>>
>

--------------NF7hO1fUSrJe30YIqsbdWqn1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hi OC,
    <ol>
      <li>not everyone that uses Groovy might be aware that a floting
        point number literal will automatically be a BD, so supporting
        g/G suffix makes total sense to let a user rest assured on what
        he will get.</li>
      <li>In addition, sometimes one wants to express in code that one
        is aware of something, in this case that a number literal is a
        BD, which again the suffix let's you express that.</li>
      <li>And finally, to me at least, supporting g/G even if it is
        syntactically speaking superfluous, is exactly what makes a
        language consistent.</li>
      <li>What I can see, is that one could want an option to directly
        express that a given integer literal shall be treated as a BD,
        without going through the rather ugly 1G.toBigDecimal()</li>
      <ol>
        <li>Which imho is also clearly worse than 1.0G .</li>
        <li>However, as this might lead to clashes with potential future
          Java suffixes I think it would be hard to come up with a good
          candidate (?)</li>
        <ol>
          <li>Which poses the question whether it would be worth the
            effort...</li>
        </ol>
      </ol>
    </ol>
    Cheers,<br>
    mg<br>
    <br>
    <div class="moz-cite-prefix">Am 20.08.2025 um 04:39 schrieb OCsite:<br>
    </div>
    <blockquote type="cite"
      cite="mid:B1C5AEBE-AB61-4E26-8797-78E3CAA0C034-CKS8FbnQINU@public.gmane.org">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      Thanks for the quick reply!
      <div><br>
      </div>
      <div>Well primarily I don't get the point of the existence of the
        BD g/G suffix at all. So that it works, the number before needs
        to contain . or e; but if so, the number is a BD anyway even
        without the suffix. Is there <i>any</i> case where the g/G BD
        suffix wouldn't be completely superfluous and adding/removing it
        would change the code behaviour in the slightest?</div>
      <div><br>
      </div>
      <div>Aside of that, there is a <i>very minute</i> and <i>completely
          unimportant</i> limitation that when I happen to need a BD
        constant whose value happens to be integral (eg., 1 or 666),
        there is (far as I know) no way to express it with a suffix in a
        format 1x, 666x (where x would be the suffix). That's somewhat
        inconsistent with other cases, e.g., 1f, 666f when the type I
        happen to need is a float.</div>
      <div><br>
      </div>
      <div>Nevertheless of course adding “.0” to get a BD is trivial and
        works reliably, thus it's really just a question of consistency,
        nothing else :)</div>
      <div><br>
      </div>
      <div>Thanks and all the best,</div>
      <div>OC<br>
        <div><br>
          <blockquote type="cite">
            <div>On 20. 8. 2025, at 3:46, Paul King
              <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a> wrote:</div>
            <br class="Apple-interchange-newline">
            <div>
              <div dir="ltr">1g or 1G gives a BigInteger and here the
                suffix is required to not get an Integer. Using 1.0g/G
                for BD seems a natural extension.
                <div><br>
                </div>
                <div>Most expressions involving both BI and BD give the
                  results you'd expect so I believe it was thought at
                  the time that using the same suffix was sufficient,
                  with toBigInteger() and toBigDecimal() allowing you to
                  swap between them if really needed.
                  <div><br>
                  </div>
                  <div>Do you have a particular scenario that you find
                    that the current conventions limit you, or are you
                    just noticing the trade-offs that were made in this
                    case and making sure you fully understand them?</div>
                  <div><br>
                  </div>
                  <div>Paul.</div>
                  <div><br>
                  </div>
                </div>
              </div>
              <br>
              <div class="gmail_quote gmail_quote_container">
                <div dir="ltr" class="gmail_attr">On Wed, Aug 20, 2025
                  at 2:13 AM OCsite &lt;<a href="mailto:[email protected]"
                    moz-do-not-send="true" class="moz-txt-link-freetext">[email protected]</a>&gt;
                  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>Hi there,
                    <div><br>
                    </div>
                    <div>I've just bumped into <a
href="https://groovy-lang.org/syntax.html#_number_type_suffixes"
                        target="_blank" moz-do-not-send="true"
                        class="moz-txt-link-freetext">https://groovy-lang.org/syntax.html#_number_type_suffixes</a>,
                      namely, to</div>
                    <div><br>
                    </div>
                    <table
style="font-variant-caps:normal;border-spacing:0px;border-collapse:collapse;color:rgb(52,52,55);font-family:&quot;Noto Sans JP&quot;,&quot;Helvetica Neue&quot;,Helvetica,Arial,sans-serif;font-size:14px">
                      <tbody style="box-sizing:border-box">
                        <tr style="box-sizing:border-box">
                          <td style="box-sizing:border-box;padding:0px">
                            <p
style="box-sizing:border-box;margin:1em 0px">BigDecimal</p>
                          </td>
                          <td style="box-sizing:border-box;padding:0px">
                            <p
style="box-sizing:border-box;margin:1em 0px"><code
style="box-sizing:border-box;font-family:Block,&quot;Noto Sans Mono&quot;,Consolas,Monaco,&quot;Bitstream Vera Sans Mono&quot;,&quot;Courier New&quot;,Courier,monospace;font-size:12.6px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-radius:4px">G</code> or <code
style="box-sizing:border-box;font-family:Block,&quot;Noto Sans Mono&quot;,Consolas,Monaco,&quot;Bitstream Vera Sans Mono&quot;,&quot;Courier New&quot;,Courier,monospace;font-size:12.6px;padding:2px 4px;color:rgb(199,37,78);background-color:rgb(249,242,244);border-radius:4px">g</code></p>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                    <div><br>
                    </div>
                    <div>which seems rather pointless to me. When one
                      enters a decimal number (e.g., 1.0), it's a BD
                      anyway, suffix or not. On the other hand, there
                      seems to be no suffix which would allow to write
                      e.g., just 1s (s for <i>something</i>) creating a
                      1 BD, which would make some sense, like e.g., 1f
                      for float does.</div>
                    <div><br>
                    </div>
                    <div>What do I overlook? What's the point of the BD
                      g/G suffix, and why there's no suffix which would
                      work without a decimal point (or exponent)?</div>
                    <div><br>
                    </div>
                    <div>Thanks,</div>
                    <div>OC</div>
                    <div><br>
                    </div>
                  </div>
                </blockquote>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>

--------------NF7hO1fUSrJe30YIqsbdWqn1--