Numeric Model

Rasmalai has no platform-dependent arithmetic. Every numeric type has a fixed width on all four backends (interpreter, Cranelift JIT, LLVM, AOT). Int and strict Float are additionally bit-identical across backends; FastFloat permits reassociation, so its last bits may differ between backends. This chapter states them exactly.

Integers: one width

Int is a 64-bit two's-complement signed integer on every platform. There are no sized integer types for general use (u8, i32, and friends do not exist in the language surface).

  • Overflow wraps modulo 2^64. There is no overflow trap and no undefined behavior.
  • Division and remainder by zero are runtime fatals. The program aborts with a diagnostic; it never produces a garbage value.
  • Literals: decimal (42), hex (0xFF), binary (0b1010), with _ digit separators (9_000). All are plain Int.
  • Conversions: Int(x) truncates a Float toward zero. Int operands inside Float arithmetic convert implicitly.
.rnx
println!(17 / 5, 17 % 5);
println!(0xFF_00, 0b1010);
println!(Int(3.9), Int(-3.9));

Bitwise operators

&, |, ^, and unary ~ operate on Int with C-style precedence (~ tightest, then &, ^, |, all above equality). Combined with hex literals they express bit patterns directly:

.rnx
let flags = 0b1010;
println!(flags & 0b0010);
println!(flags | 0b0101);
println!(flags ^ 0b1111);
println!(~0 & 0xFF);

Operator precedence and conversion reference

Arithmetic binds in this order, tightest first: unary (-x, ~x), * / %, + -, shifts (<< >> >>>), bitwise &, ^, |, comparisons, equality. Parentheses override. Mixing Float and FastFloat in one expression without an explicit conversion is an E305 error; Int operands inside Float arithmetic convert implicitly.

ExpressionResultRule
17 / 53integer division truncates toward zero
17 % 52remainder keeps the dividend sign
Int(3.9)3truncates toward zero
Int(-3.9)-3truncates toward zero, not floor
Float(7) / 2.03.5Int converts implicitly
1 << 678shift amount masks to 6 bits (shifts by 3)
(-8) >> 2-2arithmetic right shift sign-extends
(-1) >>> 19223372036854775807logical right shift zero-fills
.rnx
assert(17 / 5 == 3 && 17 % 5 == 2, "divmod");
assert(Int(3.9) == 3 && Int(-3.9) == -3, "trunc");
assert((1 << 67) == 8, "mask");
assert(((-8) >> 2) == -2, "arith shift");

Division or remainder by zero aborts with a fatal diagnostic on every backend. It never yields a value. Overflow wraps modulo 2^64 with no trap.

Math intrinsic reference

Math.sqrt, Math.sin, Math.floor, Math.log, and related intrinsics take and return Float:

CallResultEdge input
Math.sqrt(2.0)1.414...negative input yields NaN
Math.floor(3.9)3.0negative values round toward negative infinity
Math.log(0.0)negative infinitynegative input yields NaN
Float.nan()canonical 0x7FF8000000000000—
Float.isNaN(x)Booltrue only for NaN; x != x is also true for NaN
x.toBits() / Float.fromBits(b)Int / Floatexact bit round-trip
.rnx
import { Math } from "@std/math";

assert(Float.isNaN(Math.sqrt(-1.0)), "sqrt neg");
assert(Float.isNaN(Math.log(-1.0)), "log neg");
assert(Math.floor(-3.2) == -4.0, "floor neg");
let bits = 1.5.toBits();
assert(Float.fromBits(bits) == 1.5, "bits round-trip");

Shifts work on Int: << (left), >> (arithmetic right, sign-extending), >>> (logical right, zero-fill). They bind tighter than comparisons but looser than +/-, and the shift amount masks to 6 bits (1 << 67 shifts by 3). Compound forms <<=, >>=, >>>= update in place:

.rnx
println!(1 << 3);
println!((-8) >> 2);
println!((-1) >>> 1);

Float is IEEE-754 double precision with strict evaluation order: 0.1 + 0.2 behaves exactly as the standard says, identically on every backend. FastFloat is the same 64 bits with the optimizer permitted to reassociate, which can change the last bit of a result.

The type system enforces the distinction: mixing Float and FastFloat in one expression without an explicit conversion is a compile error.

  • .asFast() / .asStrict() are zero-cost marker conversions. They change the type rules, not the bits.
  • Float(x) converts an Int to Float.
  • Scientific notation needs no decimal point: 1e16, 2E+8, and 5e-3 are Float literals, exactly as written.
  • Math.sqrt, Math.sin, Math.floor, Math.log, and related intrinsics take and return Float; negative sqrt input yields NaN per IEEE-754, Math.log(0.0) yields negative infinity, and Math.log of a negative input yields NaN.
  • NaN is native IEEE-754 hardware NaN: sign and payload bits are implementation-defined and may differ between backends, matching C and Rust. Float.isNaN(x) tests for it; x != x is also true for NaN. (Float.nan() constructs the canonical 0x7FF8000000000000.)
  • The compiler never fuses a * b + c on its own for Float. For FastFloat, a multiply whose only use feeds an addition fuses into a single-rounding hardware FMA on every backend. But reassociation means the backends may fuse different multiplies (LLVM can strength-reduce x + x to 2 * x first, Cranelift does not), so FastFloat results can differ in the last bits between dev and release. Only Float is reproducible. Spelled-out fusion is Float.fma(a, b, c), one rounding, no intermediate overflow.
  • Bit accessors: Float.nan() returns canonical NaN, x.toBits() reinterprets a Float as Int bits, Float.fromBits(bits) builds a Float back with bits preserved exactly.
.rnx
import { Math } from "@std/math";

let strict: Float = 0.5;
let fast = strict.asFast();
println!(fast * 2.0.asFast());
println!(Math.sqrt(2.0) > 1.4);
println!(Float(7) / 2.0);

Interop lanes

ByteBuffer (@std/bytes) exposes the bit-level view: integer lanes read as 64-bit Int (signed lanes sign-extend, unsigned lanes zero-extend) and float lanes read as 64-bit Float. Out-of-bounds lane access aborts. This is the sanctioned path for float bitcasting and wire formats (see Hardware and FFI).

.rnx
import { ByteBuffer } from "@std/bytes";

let buf = ByteBuffer.allocate(16);
buf.writeFloat64BE(0, 1.5);
println!(buf.readFloat64BE(0));
buf.writeInt32BE(8, 0x01020304);
println!(buf.readInt32BE(8));

Summary

  • Int: 64-bit, wrapping overflow, fatal divide-by-zero, Int(x) truncates.
  • Float: strict IEEE-754 double. FastFloat: reassociation allowed, explicit .asFast() boundary required.
  • Bitwise ops on Int with C precedence; literal bases 0x/0b with _ separators.
  • Bit-level reinterpretation goes through ByteBuffer lanes.