Module: CvssSuite::Cvss31Helper

Defined in:
lib/cvss_suite/helpers/cvss31_helper.rb

Overview

This module includes methods which are used by the CVSS 3 classes.

Class Method Summary collapse

Class Method Details

.round_up(float) ⇒ Object

Since CVSS 3 all float values are rounded up, therefore this method is used instead of the mathematically correct method round(). This is the exact Roundup from CVSS v3.1 Appendix A, which works on integer arithmetic (x100000) to avoid the floating-point edge cases that plain ceil(1) hits -- the reason v3.1 replaced v3.0's rounding. https://www.first.org/cvss/v3.1/specification-document



19
20
21
22
23
24
25
26
# File 'lib/cvss_suite/helpers/cvss31_helper.rb', line 19

def self.round_up(float)
  output = (float * 100_000).round
  if (output % 10_000).zero?
    output / 100_000.0
  else
    ((output / 10_000).floor + 1) / 10.0
  end
end