Vibescript Showcase

Big integers

Work past 64 bits with transparent integer promotion — factorials, Fibonacci, crypto-sized powers, and exact JSON round trips.

Showcase
Source showcase/numbers/big_integers.vibe
# title: Big integers
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Work past 64 bits with transparent integer promotion — factorials, Fibonacci, crypto-sized powers, and exact JSON round trips.
# description: Integers promote to arbitrary precision on overflow (new in 1.0-rc2), so idiomatic Ruby code just works: reduce a factorial, iterate Fibonacci, raise 2 to the 256th. The sandbox charges big values by size, and JSON serialization stays exact instead of degrading to floats.
# tags: numbers, bignum, math
# vibe: 0.4

def factorial(n)
  (1..n).to_a.reduce(:*)
end

def fibonacci(count)
  previous = 0
  current = 1
  count.times do
    previous, current = current, previous + current
  end
  previous
end

def exact_json_round_trip?(value)
  JSON.parse(JSON.stringify(value)) == value
end

def run
  huge = factorial(50)

  {
    factorial_50: huge,
    factorial_50_digits: huge.to_s.length,
    two_to_the_256: 2 ** 256,
    fibonacci_300: fibonacci(300),
    json_stays_exact: exact_json_round_trip?(huge),
    still_an_int: huge.even?
  }
end
Output
Press run to execute run from this example.