Skip to content

Commit 695f073

Browse files
use bignum calculations for any non-integer in "multipleOf"
1 parent 569c7f3 commit 695f073

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Revision history for JSON-Schema-Tiny
33
{{$NEXT}}
44
- fix bad handling of empty patterns in "pattern",
55
"patternProperties" keywords
6+
- use bignum calculations for any non-integer in "multipleOf", to
7+
better handle overflows on older architectures
68

79
0.020 2023-04-12 03:28:28Z
810
- update test results and exemptions for TJSA 1.019

lib/JSON/Schema/Tiny.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use JSON::PP ();
2323
use List::Util 1.33 qw(any none);
2424
use Scalar::Util 'blessed';
2525
use if "$]" >= 5.022, POSIX => 'isinf';
26+
use Math::BigFloat;
2627
use namespace::clean;
2728
use Exporter 5.57 'import';
2829

@@ -453,7 +454,9 @@ sub _eval_keyword_multipleOf ($data, $schema, $state) {
453454
return 1 if not is_type('number', $data);
454455

455456
# if either value is a float, use the bignum library for the calculation
456-
if (ref($data) =~ /^Math::Big(?:Int|Float)$/ or ref($schema->{multipleOf}) =~ /^Math::Big(?:Int|Float)$/) {
457+
if (ref($data) =~ /^Math::Big(?:Int|Float)$/
458+
or ref($schema->{multipleOf}) =~ /^Math::Big(?:Int|Float)$/
459+
or get_type($data) eq 'number' or get_type($schema->{multipleOf}) eq 'number') {
457460
$data = ref($data) =~ /^Math::Big(?:Int|Float)$/ ? $data->copy : Math::BigFloat->new($data);
458461
my $divisor = ref($schema->{multipleOf}) =~ /^Math::Big(?:Int|Float)$/ ? $schema->{multipleOf} : Math::BigFloat->new($schema->{multipleOf});
459462
my ($quotient, $remainder) = $data->bdiv($divisor);

0 commit comments

Comments
 (0)