Good afternoon, tell me why sprintf does not handle some numbers and puts -000000000001 instead

 while ($AllDataRowTND=$dbqueryTND->fetchrow_arrayref()){ my $f11=sprintf("%013d",@$AllDataRowTND[9]); my $lengthf11=length(@$AllDataRowTND[9]); print @$AllDataRowTND[9]," ",$f11,"\n"; } 

Conclusion:

  147552 0000000147552 8861460504 -000000000001 3579408 0000003579408 173674665864 -000000000001 254400 0000000254400 19506120 0000019506120 78162218520 -000000000001 8259096 0000008259096 4488080280 -000000000001 2570712 0000002570712 1565484744 0001565484744 250584 0000000250584 427360243248 -000000000001 742400256 0000742400256 158498832 0000158498832 361624992816 -000000000001 59785272 0000059785272 314067564936 -000000000001 486608688 0000486608688 80281008 0000080281008 256494442128 -000000000001 
  • one
    Show that your code will print ~0 >> 1; : print ~0 >> 1; . Or this (on the command line): perl -V:[i]vsize . - PinkTux
  • Displays 2147483647 - Evgeniy A
  • It seems understood, this is a limitation of the 32-bit version of Perl, launching from under 64-bit solved the problem. - Evgeniy A
  • one
    Well yes. Or, if you need arithmetic with such numbers regardless of the architecture, you can use the Math :: Int64 module. Or maybe just the %u format will help if we are only talking about the output of unsigned ints, not exceeding 32 bits. - PinkTux
  • And for what purpose is the array cut ? - hobo-mts

1 answer 1

Perl x64 x32 maximum and minimum scalar value


  • 32-bit maximum and minimum ints and double floats: 2 to 53 degrees = 9007199254740992
  • 64-bit maximum and minimum ints and double floats: 2 to 64 degrees = 18446744073709551615, negative: -2 to 63 degrees = 9223372036854775808
  • 64-bit maximum and minimum ints and quadruple floats: 2 to 113 degrees = 10384593717069655257060992658440192

The maximum value without using Math :: BigInt in the 32 bit version will be 9007199254740992

Possible solution: my $x = Math::BigInt->new('56789012345678901234');