Class: DrLight::ScientificNumber::DevianceDistance Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dr_light/scientific_number/deviance_distance.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Responsible for calculating distance between 2 numbers in number of deviances

The combined deviance of numbers n1(d1), n2(d2) is d = sqrt(d1 ** 2 + d2 ** 2)

Examples:

With scientific number

number = DrLight::ScientificNumber.new(100, 3)
other  = DrLight::ScientificNumber.new(110, 4)

distance = DrLight::ScientificNumber::DevianceDistance.new(
  number, other
)

distance.to_f    # returns 2

With scientific number

number = DrLight::ScientificNumber.new(100, 3)
other  = 91

distance = DrLight::ScientificNumber::DevianceDistance.new(
  number, other
)

distance.to_f    # returns 3

Author:

  • Dathjee

Instance Method Summary collapse

Constructor Details

#initialize(number, other) ⇒ DevianceDistance

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of DevianceDistance.

Parameters:



37
38
39
40
41
42
43
44
45
# File 'lib/dr_light/scientific_number/deviance_distance.rb', line 37

def initialize(number, other)
  @number = number

  @other = if other.is_a?(ScientificNumber)
             other
           else
             ScientificNumber.new(other)
           end
end

Instance Method Details

#to_fFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculates the distance of numbers in deviances

Returns:

  • (Float)

    always positive number



50
51
52
53
54
# File 'lib/dr_light/scientific_number/deviance_distance.rb', line 50

def to_f
  return 0 if difference.zero?

  difference / deviance
end