Mojo-Numerics-and-Algorithms-group / NuMojo

NuMojo is a library for numerical computing in Mojo 🔥 similar to numpy in Python.
Apache License 2.0
102 stars 15 forks source link

[lib] Use macro instead of float for constants to allow compile time evaluation. #67

Closed forFudan closed 3 months ago

forFudan commented 3 months ago

Define constants.

Use alias for compile time evaluation of indefinite precision.

import numojo as nm
fn main():
    var pi: Float64 = nm.pi
    print("Float64:", pi*pi*pi*pi*pi*pi)
    print("Literal:", nm.pi*nm.pi*nm.pi*nm.pi*nm.pi*nm.pi)
Float64: 961.38919357530415
Literal: 961.38919357530449