Module: MesopotamianMath::Conversions

Includes:
Numerals
Defined in:
lib/mesopotamian_math/conversions.rb

Overview

Conversions between decimal (base 10) and sexagesimal (base 60).

Constant Summary

Constants included from Numerals

Numerals::ASH, Numerals::DISH, Numerals::DISHU, Numerals::ESH, Numerals::GESU, Numerals::GISH, Numerals::HI, Numerals::IA, Numerals::ILIMMU, Numerals::IMIN, Numerals::LIM, Numerals::LIMMU, Numerals::MAN, Numerals::MIN, Numerals::NINNU, Numerals::SHAR, Numerals::U, Numerals::UDISH, Numerals::USHU, Numerals::USSU

Class Method Summary collapse

Class Method Details

.dec_value(babylonian) ⇒ Integer

Translates simple mesopotamian numerals into integers. Only the base set of named numerals are, see Babylon::Numerals.

Parameters:

  • babylonian (String)

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mesopotamian_math/conversions.rb', line 43

def self.dec_value(babylonian)
  case babylonian
    when DISH   then 1
    when MIN    then 2
    when ESH    then 3
    when LIMMU  then 4
    when IA     then 5
    when ASH    then 6
    when IMIN   then 7
    when USSU   then 8
    when ILIMMU then 9
    when U      then 10
    when UDISH  then 11
    when MAN    then 20
    when USHU   then 30
    when HI     then 40
    when NINNU  then 50
    when GISH   then 60
    when DISHU  then 70
    when GESU   then 600
    when LIM    then 1000
    when SHAR   then 3600
  end
end

.sexa_to_string(numeral) ⇒ String

Convert a sexagesimal number, in integer or array form, into a string with babylonian cuneiform numerals.

Parameters:

Returns:

  • (String)


28
29
30
31
32
33
34
35
36
37
# File 'lib/mesopotamian_math/conversions.rb', line 28

def self.sexa_to_string(numeral)
  raise ArgumentError.new "Argument #{numeral} is neither Integer nor Array" unless (numeral.is_a?(Integer) || numeral.is_a?(Array))
  n = [numeral] if numeral.is_a? Integer
  n = numeral if numeral.is_a? Array
  result = []
  n.each do |digit|
    result << babylonian_digit(digit)
  end
  result.join "  "
end

.sexa_value(decimal) ⇒ Integer, Array

Converts an integer into sexagecimal, array syntax.

Parameters:

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/mesopotamian_math/conversions.rb', line 11

def self.sexa_value(decimal)
  raise ArgumentError.new "The argument #{decimal} is not integer" unless decimal.is_a?(Integer)
  index = 0
  input = decimal
  result = []
  while input != 0
    remainder = input % 60
    result.unshift remainder
    input = input / 60
  end
  result
end