Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 132754
Status: resolved
Priority: 0/
Queue: Type-Tiny

People
Owner: Nobody in particular
Requestors: SNEZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.010002
Fixed in: (no value)



Subject: Large integers do not pass Int
The perl version of Int uses a regular expression for validation. Since regexes work on the string representation, integers large enough to render in scientific notation fail the constraint: ``` PERL_TYPE_TINY_XS=0 perl -MTypes::Standard=is_Int -le 'my $num = 2**50; print $num, " Int: ", is_Int($num) ? "Yes" : "No"' 1.12589990684262e+15 Int: No ``` The XS version doesn't suffer from this problem.
I'd argue that the pure Perl implementation is more correct as per the documentation. Int is defined as: "An integer; that is a string of digits 0 to 9, optionally prefixed with a hyphen-minus character." If Perl's string representation of a value doesn't meet that definition, I'd argue that it should fail the check. I'm not inclined to fix this mismatch myself right now, but I would accept a patch to Type::Tiny::XS that fixes it, provided it doesn't slow down the check significantly. (Int is a commonly used type, so having a fast XS check for it is good.) And I'll make sure this gets documented as an edge case in the mean time.
Do I correctly understand you're saying your "Int" constraint will give a false negative on some integers, and you're saying you regard that false negative as not a bug?
It's not a bug in Int: use Types::Standard qw( assert_Int ); my $num = "1125899906842624"; # 2**50 assert_Int($num); # does not die The bug is that you're passing a variable containing a floating point number to it. This is like: assert_Int("the number of fingers on my left hand"); Yes, the number of my fingers on my left hand is an integer (it's 5, to be exact), but it would not be reasonable for the Int type to recognize it as such. This will also fail, even though it's an integer: assert_Int("1.00000"); The Types::Standard documentation defines Int as "a string of digits 0 to 9, optionally prefixed with a hyphen-minus character".
Documented in 1.010003.