Re: the BigDecimal g/G suffix?
Paul King <[email protected]> Wed, 20 Aug 2025 11:46:46 +1000
| Newsgroups | gmane.comp.lang.groovy.user |
|---|---|
| Message-ID | <CAMbkE7T3SH22VzVvbLODU4aFU4ChWP+CMb+bbUfbOEsNQyFMHQ@mail.gmail.com> |
--000000000000ed191f063cc2252c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFAM 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 > > --000000000000ed191f063cc2252c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">1g or 1G gives a BigInteger and here the suffix is require= d 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=C2=A0the res= ults you'd expect so I believe it was thought at the time that using th= e same suffix was sufficient, with toBigInteger() and toBigDecimal() allowi= ng you to swap between them if really needed.<div><br></div><div>Do you hav= e a particular scenario that you find that the current conventions limit yo= u, 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=3D"gmail_quote gmail_quote_contai= ner"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Aug 20, 2025 at 2:13=E2= =80=AFAM OCsite <<a href=3D"mailto:[email protected]">[email protected]</a>> wrote:= <br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8= ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi there,<= div><br></div><div>I've just bumped into=C2=A0<a href=3D"https://groovy= -lang.org/syntax.html#_number_type_suffixes" target=3D"_blank">https://groo= vy-lang.org/syntax.html#_number_type_suffixes</a>, namely, to</div><div><br= ></div><table style=3D"font-variant-caps:normal;border-spacing:0px;border-c= ollapse:collapse;color:rgb(52,52,55);font-family:"Noto Sans JP",&= quot;Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px"><tbody= style=3D"box-sizing:border-box"><tr style=3D"box-sizing:border-box"><td st= yle=3D"box-sizing:border-box;padding:0px"><p style=3D"box-sizing:border-box= ;margin:1em 0px">BigDecimal</p></td><td style=3D"box-sizing:border-box;padd= ing:0px"><p style=3D"box-sizing:border-box;margin:1em 0px"><code style=3D"b= ox-sizing:border-box;font-family:Block,"Noto Sans Mono",Consolas,= Monaco,"Bitstream Vera Sans Mono","Courier New",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>=C2=A0or=C2=A0<code styl= e=3D"box-sizing:border-box;font-family:Block,"Noto Sans Mono",Con= solas,Monaco,"Bitstream Vera Sans Mono","Courier New",C= ourier,monospace;font-size:12.6px;padding:2px 4px;color:rgb(199,37,78);back= ground-color:rgb(249,242,244);border-radius:4px">g</code></p></td></tr></tb= ody></table><div><br></div><div>which seems rather pointless to me. When on= e 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 so= me 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> --000000000000ed191f063cc2252c--