Skip to content

language: add canonical nan literals and f32/f64 NAN constants #109

Description

@julia-script

Status after the refactor

PR #125 completed the target-dependent half of the original issue: usize and isize now expose MAX, MIN, and BITS, with 32-bit/64-bit and engine coverage. That work is complete and is no longer part of this issue.

The remaining work is a source spelling for canonical floating-point NaN values and ordinary standard-library NAN constants.

Current limitation

Silk's decimal floating-point literal grammar cannot produce an IEEE NaN bit pattern. The literal-only constant-initializer rule (SEM0086) also correctly rejects computed or call-based workarounds such as 0.0 / 0.0 and f64.fromBits(...) in a constant declaration.

Runtime NaN values are already possible, so this is API and language-spelling work rather than a blocker for floating-point execution.

Decided design

  • Add a dedicated, contextually typed floating nan literal.
  • The literal defaults to f64 and becomes f32 in an f32 context.
  • It denotes the established positive canonical quiet NaN for the selected width.
  • Do not add sign or payload syntax.
  • Declare pub const NAN: f32 = nan and pub const NAN: f64 = nan in ordinary standard-library source.
  • Do not recognize the standard-library declarations by name in the compiler.
  • Keep the literal-only constant-initializer rule; do not introduce general constant evaluation.
  • Synchronize the authoritative constant specification with the already accepted target-dependent-constant delta while updating it for nan.

Out of scope

Acceptance criteria

  • The lexer/parser and semantic model accept a contextually typed nan literal.
  • An unconstrained nan defaults to f64; an f32 context produces f32.
  • f32.NAN and f64.NAN exist as ordinary standard-library constants.
  • Tests show each constant is not equal to itself.
  • Tests assert the positive canonical quiet-NaN bit pattern for each width.
  • The evaluator, native LLVM backend, and direct Wasm backend agree.
  • The OpenSpec/main specification records the literal and synchronizes the target-dependent constant rules.
  • SEM0086 continues to reject non-literal constant initializers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Clear valueenhancementNew feature or requestnew featureNew functionality outside the current stable-release language surfacespec-changeNeeds an OpenSpec amendmentstdlibSilk standard library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions