จํานวน
Translation status: ภาษาไทย reader-locale proof. Term names and code fences follow the th-TH pack; supporting prose may still be English.
An integer power never has a negative exponent: a constant one is a compile error, any other traps.
Aliases: integer, int
Syntax: <จํานวน>.power(<จํานวน>)
Category#
type
Related#
Examples#
radix/corpus/intrinseca/numerus-methodi.fab (canonical · keyword)#
Primitive integer number type.
# =============================================================================
# จํานวน — Primitive integer number type
# =============================================================================
#
# What this teaches:
# • Primitive integer number type.
# • Related keywords: เศษ, ↦
#
# Common mistakes:
# • Using `จํานวน` comparison methods on non-numeric types — `.abs()`, `.sign()`, `.minimum()`, `.maximum()` are numerus-only intrinsics.
#
# See also: เศษ, ↦
# =============================================================================
# จํานวน comparison and ordering intrinsics
#
# Compiler-owned จํานวน methodi — absolutum, signum, minimus, maximus.
#
# GRAMMAR:
# valor.abs() | valor.sign()
# valor.minimum(other) | valor.maximum(other)
#
# Integer counterpart to fractus-comparatio.fab; Wasm tier Runnable.
#
# EXPECTED OUTPUT:
# Smoke asserts exit 0 only.
main {
const int value ← -7
const int absolutus ← value.abs()
const int signum ← value.sign()
const int minor ← value.minimum(3)
const int maior ← value.maximum(3)
print absolutus, signum, minor, maior
}radix/corpus/operatores/numerus-overflow-sizes.fab (canonical · operator-group)#
Sized จํานวน arithmetic is exact; storing a value past the declared width traps.
# =============================================================================
# จํานวน — Sized จํานวน arithmetic is exact; storing past the declared width traps.
# =============================================================================
#
# What this teaches:
# • Exact intermediates — `i8` arithmetic does not overflow at 8 bits:
# `127 + 1` is 128 as a number, and it prints as 128.
# • Trap at the store — `var i8 total ← max + uno()` fails because 128
# does not fit `i8`; the program aborts with
# "128 does not fit in `i8`" and never wraps.
# • Policy distinction — every จํานวน width traps at its store; only
# `wrapping<W>` reduces mod 2^W and `saturating<W>` clamps.
#
# Common mistakes:
# • Assuming sized จํานวน wraps at the declared width like `wrapping<W>` words.
# • Expecting the trap at the `+`: the width is a property of the slot, so an
# expression with no slot (`print max + uno()`) never traps for size.
#
# See also: +, จํานวน, wrapping
# =============================================================================
# numerus-overflow-sizes — sized-width exact arithmetic, checked store
#
# POLICY:
# `i8` carries its declared width as the range of its slot. Arithmetic
# is computed exactly; the store applies the slot's policy and traps on a
# value outside -128..127. The rhs is a function call so the sum stays a
# runtime fact on every target.
fn uno() → i8 {
return 1
}
main {
var i8 max ← 127 ∷ i8
print max + uno()
var i8 total ← max + uno()
print total
}Expected output:
128
radix/corpus/operatores/numerus-overflow.fab (canonical · operator-group)#
Numerus arithmetic is exact; a value that does not fit its slot traps at the store.
# =============================================================================
# จํานวน — Numerus arithmetic is exact; a value that does not fit traps at the store.
# =============================================================================
#
# What this teaches:
# • Exact intermediates — `max + 1` is 9223372036854775808, one past the
# largest `int`; an expression is a number, not a 64-bit container, so it
# prints exactly and `max + 1 - 1` comes back to `max`.
# • Trap at the store — `var int stored ← max + 1` fails because the exact
# value does not fit `int`; the program aborts with
# "9223372036854775808 does not fit in `i64`" and never wraps.
# • The exact range — intermediates may reach [−2⁶³, 2⁶⁴ − 1]; past it
# (`max * max`) the arithmetic itself traps with "จํานวน overflow".
#
# Common mistakes:
# • Expecting `max + 1` to wrap to the minimum, or to trap where it is computed.
# • Expecting the store trap to be recoverable with `ทำ … จับ` — an implicit
# store trap is not in the `⇥` channel; use `↦ … ⊥` for a recoverable check.
# • Expecting จํานวน to wrap like modular words — use `wrapping<W>` for that.
#
# See also: +, จํานวน, wrapping
# =============================================================================
# numerus-overflow — exact arithmetic, checked store
#
# POLICY:
# Bare `จํานวน` is i64. Integer arithmetic is exact. The policy of the
# destination slot is applied where a value lands in it, and a trapping slot
# aborts on a value that does not fit. No arithmetic wraps silently.
main {
const int max ← 9223372036854775807
print max + 1
print max + 1 - 1
var int stored ← max + 1
print stored
}Expected output:
9223372036854775808
9223372036854775807
radix/corpus/operatores/numerus-widening.fab (canonical · operator-group)#
Integer arithmetic widens exactly; the slot that stores a value applies its policy.
# =============================================================================
# จํานวน — Integer arithmetic widens exactly; the slot that stores a value applies its policy.
# =============================================================================
#
# What this teaches:
# • The range rule — `u8 + u8` is computed exactly (400), not in 8 bits.
# • Untyped constants take their range — `-100 - 100` needs no width.
# • Floor division — `/` floors and `%` takes the divisor's sign.
# • True division — `÷` yields a float (`f32` for 8/16-bit operands).
# • Store policies — a trapping slot traps, `wrapping` reduces, `saturating`
# clamps; each applies where the value lands, once.
# • Comparisons are exact across signedness.
#
# Common mistakes:
# • Expecting `u8 + u8` to wrap or trap at the `+`; the check is at the store.
# • Expecting `-7 / 2` to be -3 — it floors to -4.
# • Mixing `u64` with a signed operand: `u64 + i8` is a compile error, and so
# is storing an integer in a float slot without `↦` (use `÷` for a quotient).
#
# See also: จํานวน, /, %, ÷, wrapping, saturating
# =============================================================================
# numerus-widening — the numeric model in seven short sections
fn ducenti() → u8 {
return 200
}
main {
const u8 a ← ducenti()
const u8 b ← ducenti()
# 1. Range rule: the sum is exact, and fits an i16 slot.
print a + b
const i16 wide ← a + b
print wide
# 2. Untyped constants take their range, so no operand needs a width.
print -100 - 100
const i8 low ← -100
print low - 100
# 3. Floor division; the remainder takes the divisor's sign.
print -7 / 2
print -7 % 2
print 7 % -2
# 4. True division: f64 by default, f32 for 8- and 16-bit operands.
print 7 ÷ 2
print a ÷ 3
# 5. Store policies for a value that does not fit u8.
const wrapping<u8> wrapped ← (a + b) ↦ wrapping<u8>
const saturating<u8> clamped ← (a + b) ↦ saturating<u8>
print wrapped
print clamped
# 6. `_` takes the range type; an exact value needs no narrowing.
const _ inferred ← a + b
print inferred
# 7. Comparisons are exact, including across signedness.
print a > -1
# A trapping slot aborts on a value it cannot hold; 400 does not fit in `u8`:
# const u8 bad ← a + b
# u64 with a signed operand is a compile error; convert with `↦` first:
# const u64 big ← 1
# print big + low
}Expected output:
400
400
-200
-200
-4
1
-1
3.5
66.666664
144
255
400
verum
radix/corpus/operatores/potentia-negative-exponent.fab (canonical · operator-group)#
An integer power never has a negative exponent: a constant one is a compile error, any other traps.
# =============================================================================
# จํานวน — An integer power never has a negative exponent.
# =============================================================================
#
# What this teaches:
# • Exact integer powers — `2.power(10)` is 1024 and `0.power(0)` is 1 (the
# empty product) on every family, integer and เศษ alike.
# • A constant negative exponent is a compile error — `2.power(-1)` has no
# integer value (it is 1/2), so the compiler rejects it with
# `potentia_exponent_negative`, the way it rejects a negative shift count.
# • A computed negative exponent traps — `2.power(minus())` aborts with
# "จํานวน potentia failed: negative exponent", in the class of a zero
# divisor. It is not an `⇥` failure: no handler is needed on any power.
# • เศษ keeps IEEE pow — `half.power(-1.0)` is 0.5 with no error.
#
# Common mistakes:
# • Expecting `2.power(-1)` to be 0 or 1. It is neither; use a เศษ base
# (`2.0.power(-1.0)` is 0.5).
# • Expecting the trap to be recoverable with `ทำ … จับ`.
#
# See also: จํานวน, เศษ, wrapping
# =============================================================================
# potentia-negative-exponent — integer power, negative exponent
#
# POLICY:
# `x.power(n)` on an integer needs n ≥ 0. The exponent of `2.power(-1)` is a
# constant, so the program would not compile; the exponent below comes from a
# function call, so the check is a runtime fact on every target.
fn minus() → int {
return -1
}
main {
print 2.power(10)
print 0.power(0)
const float half ← 2.0
print half.power(-1.0)
print 2.power(minus())
print 99
}Expected output:
1024
1
0.5
radix/corpus/typi/numerus-hole-error.fab (supporting · reject)#
Retired numeric marker hole จํานวน<_> (expect parse error).
# =============================================================================
# จํานวน — Retired numeric marker hole (expect parse error).
# =============================================================================
#
# What this teaches:
# • The marker holes `จํานวน<_>` and `เศษ<_>` (en `int<_>` / `float<_>`) retired with the wrapped numeric spelling; there is no wrapped form left to leave a hole in
# • Parse error — `PARSE040:numeric_wrapper_retired` names the form written; bare `จํานวน` is the default `i64`, and a bare marker such as `i32` is the sized type
# • The policy words keep their hole (`โมดูลัส<_>`, `อิ่มตัว<_>`)
#
# Common mistakes:
# • writing `จํานวน<_>` to let the width be inferred — name the marker (`i32`) or use bare `จํานวน`
#
# See also: จํานวน, เศษ
# =============================================================================
# retired numeric marker hole (expect parse error)
#
# WHY: a width marker is its own type; the wrapped form, holes included, is retired.
#
# DELIBERATE: this exemplum keeps the retired spelling (`int<_>`) on purpose, to
# pin the PARSE040 `numeric_wrapper_retired` diagnostic for the hole form (N7d).
main {
const int<_> width ← 1 ∷ i32
print width
}Expected: compilation rejects this example.