note
haukex
<blockquote><i>I have seen that 'int' can do weird things, and I am not convinced that there is no floating-point corner case somewhere on some hardware that spits out something that looks like an integer, because some inaccuracy cancels out when generating a string from it.</i></blockquote>
<p>Of course, if you could show an example of this, that'd be much better than a vauge worry. [doc://int] is documented to return an integer, and [hippo]'s [id://11118680|<c>valid_int</c>] includes a check that the input is not floating-point.</p>
<p>If you're worried about a cutoff happening at 9,007,199,254,740,991 instead of 9,007,199,254,740,992, both of which are over nine quadrillion, then I suggest you're worrying about the wrong thing: since you're saying you want this to be portable to different machines and different Perls, <i>this cutoff is <b>arbitrary</b> anyway!</i></p>
<p>If you want a precise cutoff, you should choose a specific one that you are pretty certain will work on all expected architectures, like say <c>2**31-1</c>, and if you wanted to code super defensively, you can even compare this cutoff to the integer limits I [id://11108835|linked to] and report an error otherwise.</p>
<blockquote><i>Besides, the "eq" is actually converting the integer back to a string, which will cost performance.</i></blockquote>
<p>[hippo] [id://11118710|beat me to it]: Perl's internal conversions are very fast, I suspect it'll be negligible. But let's not guess - [doc://Benchmark]!</p>
11118650
11118705