… | |
… | |
1019 | decimal fractions is generally fast. Decoding bigints can be slow for very |
1019 | decimal fractions is generally fast. Decoding bigints can be slow for very |
1020 | big numbers, and decoding bigfloats or arbitrary-exponent bigfloats can be |
1020 | big numbers, and decoding bigfloats or arbitrary-exponent bigfloats can be |
1021 | extremely slow (minutes, decades) for large exponents. |
1021 | extremely slow (minutes, decades) for large exponents. |
1022 | |
1022 | |
1023 | Additionally, L<Math::BigInt> can take advantage of other bignum |
1023 | Additionally, L<Math::BigInt> can take advantage of other bignum |
1024 | libraries, such as L<Math::GMP> or L<Math::Pari>, which cannot handle big |
1024 | libraries, such as L<Math::GMP>, which cannot handle big |
1025 | floats with large exponents, and might simply abort or crash your program, |
1025 | floats with large exponents, and might simply abort or crash your program, |
1026 | due to their code quality. |
1026 | due to their code quality. |
1027 | |
1027 | |
1028 | This can be a concern if you want to parse untrusted CBOR. If it is, you |
1028 | This can be a concern if you want to parse untrusted CBOR. If it is, you |
1029 | need to disable decoding of tag 2 (bigint) and 3 (negative bigint) types, |
1029 | need to disable decoding of tag 2 (bigint) and 3 (negative bigint) types, |
1030 | which will also disable bigfloat support (to be sure, you can also disable |
1030 | which will also disable bigfloat support (to be sure, you can also disable |
1031 | types 5 and 265). |
1031 | types 4, 5, 264 and 265). |
1032 | |
1032 | |
1033 | |
1033 | |
1034 | =head1 CBOR IMPLEMENTATION NOTES |
1034 | =head1 CBOR IMPLEMENTATION NOTES |
1035 | |
1035 | |
1036 | This section contains some random implementation notes. They do not |
1036 | This section contains some random implementation notes. They do not |
… | |
… | |
1110 | scalar Time::Piece::gmtime (pop) |
1110 | scalar Time::Piece::gmtime (pop) |
1111 | }, |
1111 | }, |
1112 | |
1112 | |
1113 | 2 => sub { # pos bigint |
1113 | 2 => sub { # pos bigint |
1114 | require Math::BigInt; |
1114 | require Math::BigInt; |
1115 | Math::BigInt->new ("0x" . unpack "H*", pop) |
1115 | Math::BigInt->from_hex ("0x" . unpack "H*", pop) |
1116 | }, |
1116 | }, |
1117 | |
1117 | |
1118 | 3 => sub { # neg bigint |
1118 | 3 => sub { # neg bigint |
1119 | require Math::BigInt; |
1119 | require Math::BigInt; |
1120 | -Math::BigInt->new ("0x" . unpack "H*", pop) |
1120 | -Math::BigInt->from_hex ("0x" . unpack "H*", pop) |
1121 | }, |
1121 | }, |
1122 | |
1122 | |
1123 | 4 => sub { # decimal fraction, array |
1123 | 4 => sub { # decimal fraction, array |
1124 | require Math::BigFloat; |
1124 | require Math::BigFloat; |
1125 | Math::BigFloat->new ($_[1][1] . "E" . $_[1][0]) |
1125 | Math::BigFloat->new ($_[1][1] . "E" . $_[1][0]) |