Vibescript Showcase

Numeric literals and rounding

Read base-prefix and scientific literals, then round and inspect numbers with Ruby-style helpers.

Showcase
Source showcase/numbers/literals_and_rounding.vibe
# title: Numeric literals and rounding
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Read base-prefix and scientific literals, then round and inspect numbers with Ruby-style helpers.
# description: 1.0 adds hex, octal, binary, and exponent literals plus rounding and predicate helpers, so bit flags, byte sizes, and money-adjacent math read the way they do in Ruby.
# tags: numbers, literals, math
# vibe: 0.4

def permission_bits
  {
    read: 0b100,
    write: 0b010,
    execute: 0b001,
    read_write: 0b100 + 0b010
  }
end

def named_sizes
  {
    kilobyte: 1e3,
    megabyte: 1e6,
    hex_flags: 0xFF00,
    octal_mode: 0o755
  }
end

def rounding(value: float) -> hash
  {
    whole: value.round,
    cents: value.round(2),
    down: value.floor,
    up: value.ceil
  }
end

def run
  {
    permission_bits: permission_bits,
    named_sizes: named_sizes,
    rounding: rounding(3.14159),
    is_even: 42.even?,
    next_id: 41.succ
  }
end
Output
Press run to execute run from this example.