Class: Dcc::QuantityMath::Real
Overview
BigDecimal arithmetic on real-valued quantities with RSS uncertainty
propagation for add/sub and fractional propagation for mul/div.
Instance Attribute Summary
Attributes inherited from Quantity
#uncertainty, #unit, #value
Instance Method Summary
collapse
Methods inherited from Quantity
#initialize, #same_unit?, #to_s, #uncertain?
Instance Method Details
#*(other) ⇒ Real
31
32
33
34
35
36
37
38
39
|
# File 'lib/dcc/quantity_math/real.rb', line 31
def *(other)
new_value = value * other.value
new_unit = compose_unit(unit, other.unit)
Real.new(
value: new_value,
unit: new_unit,
uncertainty: fractional_uncertainty_mul_div(other, new_value),
)
end
|
#**(exponent) ⇒ Real
54
55
56
57
58
59
60
61
|
# File 'lib/dcc/quantity_math/real.rb', line 54
def **(exponent)
new_value = value ** exponent
Real.new(
value: new_value,
unit: unit && "^#{exponent}",
uncertainty: power_uncertainty(exponent, new_value),
)
end
|
#+(other) ⇒ Real
11
12
13
14
15
16
17
18
|
# File 'lib/dcc/quantity_math/real.rb', line 11
def +(other)
ensure_same_unit!(other)
Real.new(
value: value + other.value,
unit: unit,
uncertainty: (other),
)
end
|
#-(other) ⇒ Real
21
22
23
24
25
26
27
28
|
# File 'lib/dcc/quantity_math/real.rb', line 21
def -(other)
ensure_same_unit!(other)
Real.new(
value: value - other.value,
unit: unit,
uncertainty: (other),
)
end
|
#/(other) ⇒ Real
42
43
44
45
46
47
48
49
50
|
# File 'lib/dcc/quantity_math/real.rb', line 42
def /(other)
new_value = value / other.value
new_unit = compose_unit(unit, inverse_unit(other.unit))
Real.new(
value: new_value,
unit: new_unit,
uncertainty: fractional_uncertainty_mul_div(other, new_value),
)
end
|