def to_base
return self if self.is_base?
if self.units =~ /\A(deg|temp)(C|F|K|C)\Z/
@signature = 400
base = case self.units
when /temp/ : self.to('tempK')
when /deg/ : self.to('degK')
end
return base
end
cached = ((@@base_unit_cache[self.units] * self.scalar) rescue nil)
return cached if cached
num = []
den = []
q = 1
for unit in @numerator.compact do
if @@PREFIX_VALUES[unit]
q *= @@PREFIX_VALUES[unit]
else
q *= @@UNIT_VALUES[unit][:scalar] if @@UNIT_VALUES[unit]
num << @@UNIT_VALUES[unit][:numerator] if @@UNIT_VALUES[unit] && @@UNIT_VALUES[unit][:numerator]
den << @@UNIT_VALUES[unit][:denominator] if @@UNIT_VALUES[unit] && @@UNIT_VALUES[unit][:denominator]
end
end
for unit in @denominator.compact do
if @@PREFIX_VALUES[unit]
q /= @@PREFIX_VALUES[unit]
else
q /= @@UNIT_VALUES[unit][:scalar] if @@UNIT_VALUES[unit]
den << @@UNIT_VALUES[unit][:numerator] if @@UNIT_VALUES[unit] && @@UNIT_VALUES[unit][:numerator]
num << @@UNIT_VALUES[unit][:denominator] if @@UNIT_VALUES[unit] && @@UNIT_VALUES[unit][:denominator]
end
end
num = num.flatten.compact
den = den.flatten.compact
num = UNITY_ARRAY if num.empty?
base= Unit.new(Unit.eliminate_terms(q,num,den))
@@base_unit_cache[self.units]=base
return base * @scalar
end