Files
news.gitea.happylizard.me/bin/gems/ttfunk-1.8.0/lib/ttfunk/sci_form.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

47 lines
950 B
Ruby

# frozen_string_literal: true
module TTFunk
# Scientific number representation
class SciForm
# Significand
# @return [Float, Integer]
attr_reader :significand
# Exponent
# @return [Float, Integer]
attr_reader :exponent
# @param significand [Float, Integer]
# @param exponent [Float, Integer]
def initialize(significand, exponent = 0)
@significand = significand
@exponent = exponent
end
# Convert to Float.
#
# @return [Float]
def to_f
significand * (10**exponent)
end
# Check equality to another number.
#
# @param other [Float, SciForm]
# @return [Boolean]
def ==(other)
case other
when Float
other == to_f # rubocop: disable Lint/FloatComparison
when self.class
other.significand == significand &&
other.exponent == exponent
else
false
end
end
alias eql? ==
end
end