Re: the BigDecimal g/G suffix?
OCsite <[email protected]> Wed, 20 Aug 2025 04:39:44 +0200
| Newsgroups | gmane.comp.lang.groovy.user |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_669F9004-C1B5-44D7-B379-9C37F6006B2E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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 =E2=80=9C.0=E2=80=9D 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: >=20 > 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. >=20 > 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. >=20 > 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? >=20 > Paul. >=20 >=20 > On Wed, Aug 20, 2025 at 2:13=E2=80=AFAM OCsite <[email protected] = <mailto:[email protected]>> wrote: >> Hi there, >>=20 >> I've just bumped into = https://groovy-lang.org/syntax.html#_number_type_suffixes, namely, to >>=20 >> BigDecimal >>=20 >> G or g >>=20 >>=20 >> 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. >>=20 >> 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)? >>=20 >> Thanks, >> OC >>=20 --Apple-Mail=_669F9004-C1B5-44D7-B379-9C37F6006B2E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 <html><head><meta http-equiv=3D"content-type" content=3D"text/html; = charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; = -webkit-nbsp-mode: space; line-break: after-white-space;">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 = =E2=80=9C.0=E2=80=9D 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=3D"cite"><div>On 20. 8. = 2025, at 3:46, Paul King <[email protected]> wrote:</div><br = class=3D"Apple-interchange-newline"><div><div dir=3D"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=3D"gmail_quote gmail_quote_container"><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.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=3D"https://groovy-lang.org/syntax.html#_number_type_suffixes" = target=3D"_blank">https://groovy-lang.org/syntax.html#_number_type_suffixe= s</a>, namely, to</div><div><br></div><table = style=3D"font-variant-caps:normal;border-spacing:0px;border-collapse:colla= pse;color:rgb(52,52,55);font-family:"Noto Sans = JP","Helvetica = Neue",Helvetica,Arial,sans-serif;font-size:14px"><tbody = style=3D"box-sizing:border-box"><tr style=3D"box-sizing:border-box"><td = style=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;padding:0px"><p = style=3D"box-sizing:border-box;margin:1em 0px"><code = style=3D"box-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:4= px">G</code> or <code = style=3D"box-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:4= px">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></d= iv></div></blockquote></div> </div></blockquote></div><br></div></body></html>= --Apple-Mail=_669F9004-C1B5-44D7-B379-9C37F6006B2E--