Re: Math::BigInt and bigint with non-integers
[email protected] (Peter John Acklam) Fri, 20 Aug 2021 15:10:40 +0200
| Newsgroups | perl.module-authors |
|---|---|
| Message-ID | <CAEvoY42KTe9wsxTOrHSFY5xmPVDTjuWfAB1eW8bO6hMF2KdXvg@mail.gmail.com> |
--0000000000009e0ed105c9fd6553 Content-Type: text/plain; charset="UTF-8" tor. 19. aug. 2021 kl. 16:40 skrev Dan Book <[email protected]>: > > > Truncation to integer seems the most useful and expected behavior to me. Not sure if the "overloading of constants" case should be affected, would people depend on it staying unmodified? I agree on truncation to integer. This is consistent with how Perl treats non-integers in integer context. E.g., $a[0.9] returns $a[0], not $a[1]. I know nothing about the context in which people use "use Math::BigInt=:constant" or "use bigint". I would suspect that these are only used when people are using integers only. As soon as a non-integer interacts with the overloaded literal integers, it is converted to an integer (with "bignum") $ perl -Mbigint -wle 'print 2 + 3.16' 5 or a NaN (with "Math::BigInt") $ perl -MMath::BigInt=:constant -wle 'print 2 + 3.16' NaN It seems most sensible to me that both cases should return 5. It would be nice if Math::BigInt->new("3.16") also returned 3, not NaN as now. However, people might rely on this behaviour. I might search through the CPAN modules and see if I can find any use cases. Peter --0000000000009e0ed105c9fd6553 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">tor. 19. aug. 2021 kl. 16:40 skrev Dan Book <<a href=3D= "mailto:[email protected]">[email protected]</a>>:<br>><br>><br>>= Truncation to integer seems the most useful and expected behavior to me. N= ot sure if the "overloading of constants" case should be affected= , would people depend on it staying unmodified?<br><br>I agree on truncatio= n to integer. This is consistent with how Perl treats non-integers in integ= er context. E.g., $a[0.9] returns $a[0], not $a[1].<br><br>I know nothing a= bout the context in which people use "use Math::BigInt=3D:constant&quo= t; or "use bigint". I would suspect that these are only used when= people are using integers only. As soon as a non-integer interacts with th= e overloaded literal integers, it is converted to an integer (with "bi= gnum")<br><br>=C2=A0 =C2=A0 $ perl -Mbigint -wle 'print 2 + 3.16&#= 39;<br>=C2=A0 =C2=A0 5<br><br>or a NaN (with "Math::BigInt")<br><= br>=C2=A0 =C2=A0 $ perl -MMath::BigInt=3D:constant -wle 'print 2 + 3.16= '<br>=C2=A0 =C2=A0 NaN<br><br>It seems most sensible to me that both ca= ses should return 5.<br><br>It would be nice if Math::BigInt->new("= 3.16") also returned 3, not NaN as now. However, people might rely on = this behaviour. I might search through the CPAN modules and see if I can fi= nd any use cases.<br><br>Peter<br></div> --0000000000009e0ed105c9fd6553--