渲染zh-Hans

≅

Translation status: 简体中文 reader-locale proof. Term names and code fences follow the zh-Hans pack; supporting prose may still be English.

Numeric value equality (≅) after promotion join — exact, not fuzzy float.

Syntax: <expression> ≅ <expression> | <expression> ≇ <expression>

Category#

comparison

Examples#

radix/corpus/operatores/numeric-value-eq.fab (canonical · operator)#

Numeric value equality (≅) after promotion join — exact, not fuzzy float.

# =============================================================================
# ≅ — Numeric value equality after promotion join — not fuzzy float.
# =============================================================================
#
# What this teaches:
#   • Value equality — `≅` promotes numeric types to a common width before comparing.
#   • Exact comparison — Unlike `≡`, `≅` works across numeric widths (u8 vs i64), but still exact.
#   • Exact joins — signed negatives do not wrap into unsigned values, and an integer is never rounded to a float first, so integers above 2^53 stay distinct from the float beside them.
#
# Common mistakes:
#   • Expecting ≅ to be fuzzy or approximate — it is exact value equality after promotion.
#   • Treating −1 as the unsigned maximum — the sign-boundary comparison is 假, not a wrapped match.
#
# See also: ≡, ≠, ↦, 断言
# =============================================================================

# operatores/numeric-value-eq — ≅ ≇
#
# WHY: ≡ requires identical types; ≅ compares the true values of any two numerics.
# 42.145 ≅ 42 must stay false (no hidden tolerance).

main {
    const u8 port ← 42 ∷ u8
    const int count ← 42
    const _ same_width ← port ≅ count
    print same_width

    const _ int_float ← 1 ≅ 1.0
    print int_float

    const _ not_fuzzy ← 42.145 ∷ f64 ≅ 42.0 ∷ f64
    print not_fuzzy

    const _ differs ← 1 ≇ 2
    print differs

    # Sign-boundary pin: a negative signed value never wraps to u64::MAX.
    const i64 signed_negative ← -1
    const u64 unsigned_max ← 18446744073709551615
    const _ sign_equal ← signed_negative ≅ unsigned_max
    const _ sign_different ← signed_negative ≇ unsigned_max
    print sign_equal
    print sign_different

    # Cross-width pin: the 2^53+1 integer remains distinct from 2^53.
    const i64 above_precision ← 9007199254740993
    const u64 below_precision ← 9007199254740992
    const _ cross_width ← above_precision ≅ below_precision
    print cross_width

    # Exactness pin: 2^53+1 is not representable as f64, so it is not equal to
    # the float 2^53 (comparison never rounds the integer side).
    const f64 float_boundary ← 9007199254740992.0
    const bool int_float_honesty ← above_precision ≅ float_boundary
    print int_float_honesty
}

Expected output:

verum
verum
falsum
verum
falsum
verum
falsum
falsum