-# A general number class, currently supporting integral Javascript numbers,
+# A generic number type, currently supporting integral Javascript numbers,
 # arbitrary precision integers and fractions.
 #
 # Arguments and results of arithmetic operations are coerced to the best

# Here are the beginnings of the `LongInt` class.

class LongInt
  make_digits = (m) ->
    if m then seq.conj m % BASE, -> make_digits (m / BASE) >> 0 else null

  constructur: (n = 0) ->
    [m, @sign] = if n < 0 then [-n, -1] else [n, 1]
    @digits = make_digits m

  times: (other) ->

  zeroes = BASE.toString()[1..]


#
# In production mode, the number `BASE` is computed as the largest power of 100
# that fits into a Javascript number twice with full precision. The number
# `HALFBASE` it its square root. According to the Javascript specification, we
# should expect `BASE == 10e14` and `HALFBASE == 10e7`.

BASE_LENGTH = if quicktest then 4 else
  seq.from(1)
    .map((n) -> 2 * n)
    .takeWhile((n) ->
      b = Math.pow 10, n
      2 * b - 2 != 2 * b - 1 and -2 * b + 2 != -2 * b + 1
    )
    .last()

BASE     = Math.pow 10, BASE_LENGTH
HALFBASE = Math.sqrt BASE

# ----

# Internal helpers for constructing number representations.

asNum = (n) ->
  if Math.abs(n) < BASE then new CheckedInt n else LongInt.fromNative n

digits = (m) ->
  if m then seq.conj m % BASE, -> digits Math.floor(m / BASE) else null

# ----

