in reply to Number too big to fit in integer

Is there a simpler way to ensure arguments fit in integers?

I believe so.
If people would just break away from the notion that it's ok to use a perl whose NV precision is less than its IV precision, then you could just do something like the obvious:
die "value is too large if $value > ~0;
AFAIK, that works fine on any perl whose nvsize is greater than 8 bytes (ie nvtype is either 'long double' or '__float128').
Unfortunately, the general go-to perl configuration is one where NV precision is less than IV precision.
Anyone (frequently including me) who uses such a perl either doesn't care about arithmetic (not me), enjoys performing mental contortions (not me), is plain stupid, or is on some perverse and antiquated system that doesn't provide for an nvsize > 8 (not me).
Are there any other explanations ?

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Number too big to fit in integer
by hv (Prior) on Dec 26, 2022 at 05:39 UTC

    It is probably not wise to try to categorize the reasons why someone might disagree with a point of view, particularly if "just plain stupid" is one of the categories.

    I generally don't need to care what my NV precision is. If I am dealing with integers that can get anywhere near the safe limit (which is a lot of the time), I use a bigint library.

      If I am dealing with integers that can get anywhere near the safe limit (which is a lot of the time), I use a bigint library.

      Fair enough, but all the OP wanted was to test whether a positive integer value was greater than ~0.
      If you think it's fair enough that checking whether $non_negative_integer_value > ~0 should not necessarily be sufficient, then that's fine by me - you've got what you want, and you're welcome to stick with your 64-bit precision IV & 53-bit precision NV perl configuration.

      To me, the behaviour (re integer-float conversions) on this and only this IV/NV configuration is interesting and challenging, up to a point. But it's poorly thought out (if it was ever actually thought out at all), and having to deal with it is counter-productive. Perl is supposed to DWIM and to make things easier, and this particular configuration falls down in those 2 regards.
      That, nearly a quarter of the way through the 21st century this configuration is still arguably the most prevalent by far, makes me wonder about the mental acuity of perl programmers - at least those perl programmers that are interested in perl's math operations.
      OTOH, for all other possible IV/NV permutations perl's math behaviour (re integer-float conversions) is sane, helpful, DWIMs, and makes things easier.

      Cheers,
      Rob

        makes me wonder about the mental acuity of perl programmers

        That's twice now that you have stated anyone who doesn't care about the same things as you do, in the same way, must be stupid. Please stop doing that.