Skip to content

Commit

Permalink
Fix rounding (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
skontar authored Sep 7, 2024
1 parent e4cf69b commit 89801dc
Show file tree
Hide file tree
Showing 7 changed files with 578,859 additions and 578,867 deletions.
2 changes: 1 addition & 1 deletion cvss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .exceptions import CVSS2Error, CVSS3Error, CVSS4Error, CVSSError
from .interactive import ask_interactively

__version__ = "3.1"
__version__ = "3.2"
16 changes: 4 additions & 12 deletions cvss/cvss4.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from __future__ import unicode_literals

import copy
from decimal import ROUND_CEILING, ROUND_HALF_UP
from decimal import ROUND_HALF_UP
from decimal import Decimal as D

from .constants4 import (
Expand All @@ -52,16 +52,8 @@
from .exceptions import CVSS4MalformedError, CVSS4MandatoryError


def round_away_from_zero(x, dp):
return float(D(x).quantize(D("0." + "0" * dp), rounding=ROUND_HALF_UP))


def round_up(value):
"""
Round up is defined as the smallest number, specified to one decimal place, that is equal to
or higher than its input. For example, Round up (4.02) is 4.1; and Round up (4.00) is 4.0.
"""
return value.quantize(D("0.1"), rounding=ROUND_CEILING)
def round_away_from_zero(x):
return float(D(x * 10).quantize(D("1"), rounding=ROUND_HALF_UP) / 10)


class CVSS4(object):
Expand Down Expand Up @@ -555,7 +547,7 @@ def compute_base_score(self):
value = max(0.0, value)
value = min(10.0, value)

self.base_score = round_away_from_zero(value, 1)
self.base_score = round_away_from_zero(value)

def __hash__(self):
return hash(self.clean_vector())
Expand Down
209,952 changes: 104,976 additions & 104,976 deletions tests/vectors_base4

Large diffs are not rendered by default.

Loading

0 comments on commit 89801dc

Please sign in to comment.