Skip to content

Commit b9dc7c4

Browse files
author
Sebastian Mika
committed
Closes maximum issue which wasn't an issue.
Remove float conversion on minimum validator to make it work for very negative numbers
1 parent 458022d commit b9dc7c4

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

json/tests/draft3/optional/bignum.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@
2121
}
2222
]
2323
},
24+
{
25+
"description": "integer",
26+
"schema": {"type": "integer"},
27+
"tests": [
28+
{
29+
"description": "a negative bignum is an integer",
30+
"data": -12345678910111213141516171819202122232425262728293031,
31+
"valid": true
32+
}
33+
]
34+
},
35+
{
36+
"description": "number",
37+
"schema": {"type": "number"},
38+
"tests": [
39+
{
40+
"description": "a negative bignum is a number",
41+
"data": -98249283749234923498293171823948729348710298301928331,
42+
"valid": true
43+
}
44+
]
45+
},
2446
{
2547
"description": "string",
2648
"schema": {"type": "string"},
@@ -56,5 +78,30 @@
5678
"valid": false
5779
}
5880
]
81+
},
82+
{
83+
"description": "integer comparison",
84+
"schema": {"minimum": -18446744073709551615},
85+
"tests": [
86+
{
87+
"description": "comparison works for very negative numbers",
88+
"data": -18446744073709551600,
89+
"valid": true
90+
}
91+
]
92+
},
93+
{
94+
"description": "float comparison with high precision on negative numbers",
95+
"schema": {
96+
"minimum": -972783798187987123879878123.18878137,
97+
"exclusiveMinimum": true
98+
},
99+
"tests": [
100+
{
101+
"description": "comparison works for very negative numbers",
102+
"data": -972783798187987123879878123.188781371,
103+
"valid": false
104+
}
105+
]
59106
}
60107
]

jsonschema/_validators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ def minimum(validator, minimum, instance, schema):
7777
return
7878

7979
if schema.get("exclusiveMinimum", False):
80-
failed = float(instance) <= float(minimum)
80+
failed = instance <= minimum
8181
cmp = "less than or equal to"
8282
else:
83-
failed = float(instance) < float(minimum)
83+
failed = instance < minimum
8484
cmp = "less than"
8585

8686
if failed:
@@ -94,10 +94,10 @@ def maximum(validator, maximum, instance, schema):
9494
return
9595

9696
if schema.get("exclusiveMaximum", False):
97-
failed = float(instance) >= float(maximum)
97+
failed = instance >= maximum
9898
cmp = "greater than or equal to"
9999
else:
100-
failed = float(instance) > float(maximum)
100+
failed = instance > maximum
101101
cmp = "greater than"
102102

103103
if failed:

0 commit comments

Comments
 (0)