Skip to content

Add named math constants (PI, E, TAU) #105

@timfennis

Description

@timfennis

Summary

The language currently has no named constants for common mathematical values. Users have to write magic number literals like 3.14159265358979... when working with trigonometry.

Proposed constants

  • PI (or pi) — π ≈ 3.141592653589793
  • E (or e) — Euler's number ≈ 2.718281828459045
  • TAU (or tau) — 2π ≈ 6.283185307179586
  • Inf — positive infinity (already exists as a float literal)
  • NaN — not-a-number (already exists as a float literal)

Motivation

Came up when writing tests for trig functions (023_trig_functions.ndc) — to test sin(pi/2) == 1.0 we had to inline 1.5707963267948966 as a magic number, which is fragile and unreadable.

Possible implementation

Register as global constants in ndc_stdlib/src/math.rs, similar to how NaN and Inf are likely handled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions