componentized/directory

componentized:constants

interface

Create custom wasm components that export constant values.

interface math componentized:constants/math@0.2.0

Common mathematical constants and sequences.

Functions

functione: func() -> f64

Euler's number (e) @value 2.718281828459045

functioneuler-gamma: func() -> f64

The Euler-Mascheroni constant (γ) @value 0.5772156649015329

functionfrac-n1-pi: func() -> f64

1/π @value 0.3183098861837907

functionfrac-n1-sqrt-n2: func() -> f64

1/sqrt(2) @value 0.7071067811865476

functionfrac-n2-pi: func() -> f64

2/π @value 0.6366197723675814

functionfrac-n2-sqrt-pi: func() -> f64

2/sqrt(π) @value 1.1283791670955126

functionfrac-pi-n2: func() -> f64

π/2 @value 1.5707963267948966

functionfrac-pi-n3: func() -> f64

π/3 @value 1.0471975511965979

functionfrac-pi-n4: func() -> f64

π/4 @value 0.7853981633974483

functionfrac-pi-n6: func() -> f64

π/6 @value 0.5235987755982989

functionfrac-pi-n8: func() -> f64

π/8 @value 0.39269908169872414

functiongolden-ratio: func() -> f64

The golden ratio (φ) @value 1.618033988749895

functionln-n2: func() -> f64

ln(2) @value 0.6931471805599453

functionln-n10: func() -> f64

ln(10) @value 2.302585092994046

functionlog2-n10: func() -> f64

log2(10) @value 3.321928094887362

functionlog2-e: func() -> f64

log2(e) @value 1.4426950408889634

functionlog10-n2: func() -> f64

log10(2) @value 0.3010299956639812

functionlog10-e: func() -> f64

log10(e) @value 0.4342944819032518

functionpi: func() -> f64

Archimedes' constant (π) @value 3.141592653589793

functionsqrt-n2: func() -> f64

sqrt(2) @value 1.4142135623730951

functiontau: func() -> f64

The full circle constant (τ) @value 6.283185307179586

async functionodd: async func() -> stream<u64>

Odd numbers. Stream closes when it reaches max int. @value [1] @expression |v| v + 2

async functioneven: async func() -> stream<u64>

Even numbers. Stream closes when it reaches max int. @value [0] @expression |v| v + 2

async functionarithmetic: async func(n: u64, d: u64) -> stream<u64>

Arithmetic sequence. Stream closes when it reaches max int. @expression || n + d * $i

async functiongeometric: async func(n: u64, r: u64) -> stream<u64>

Geometric sequence. Stream closes when it reaches max int. @expression || n * r ** $i

async functionfibonacci: async func() -> stream<u64>

Fibonacci sequence. Stream closes when it reaches max int. @value [1, 1] @expression |a, b| a + b

async functionfactorial: async func() -> stream<u64>

Factorial sequence. Stream closes when it reaches max int. @value [1, 1] @expression |v| v * $i

async functionharmonic: async func(n: f64) -> stream<f64>

Harmonic sequence. Stream closes when it reaches min-positive. @expression || n / ($i + 1) as f64

async functionfigurate: async func(n: u64) -> stream<u64>

Figurate sequence. Stream closes when it reaches max int. @expression || $i ** n

async functionprime: async func() -> stream<u64>

Prime numbers, each found by trial division from the previous one. Stream closes when it reaches max int. @value [2] @expression |v| { let mut n = v + 1; let mut d: u64 = 2; while d * d <= n { if n % d == 0 { n += 1; d = 2; } else { d += 1; } } n }

WIT

/// Common mathematical constants and sequences.
interface math {
  /// Euler's number (e)
  /// @value 2.718281828459045
  e: func() -> f64;

  /// The Euler-Mascheroni constant (γ)
  /// @value 0.5772156649015329
  euler-gamma: func() -> f64;

  /// 1/π
  /// @value 0.3183098861837907
  frac-n1-pi: func() -> f64;

  /// 1/sqrt(2)
  /// @value 0.7071067811865476
  frac-n1-sqrt-n2: func() -> f64;

  /// 2/π
  /// @value 0.6366197723675814
  frac-n2-pi: func() -> f64;

  /// 2/sqrt(π)
  /// @value 1.1283791670955126
  frac-n2-sqrt-pi: func() -> f64;

  /// π/2
  /// @value 1.5707963267948966
  frac-pi-n2: func() -> f64;

  /// π/3
  /// @value 1.0471975511965979
  frac-pi-n3: func() -> f64;

  /// π/4
  /// @value 0.7853981633974483
  frac-pi-n4: func() -> f64;

  /// π/6
  /// @value 0.5235987755982989
  frac-pi-n6: func() -> f64;

  /// π/8
  /// @value 0.39269908169872414
  frac-pi-n8: func() -> f64;

  /// The golden ratio (φ)
  /// @value 1.618033988749895
  golden-ratio: func() -> f64;

  /// ln(2)
  /// @value 0.6931471805599453
  ln-n2: func() -> f64;

  /// ln(10)
  /// @value 2.302585092994046
  ln-n10: func() -> f64;

  /// log2(10)
  /// @value 3.321928094887362
  log2-n10: func() -> f64;

  /// log2(e)
  /// @value 1.4426950408889634
  log2-e: func() -> f64;

  /// log10(2)
  /// @value 0.3010299956639812
  log10-n2: func() -> f64;

  /// log10(e)
  /// @value 0.4342944819032518
  log10-e: func() -> f64;

  /// Archimedes' constant (π)
  /// @value 3.141592653589793
  pi: func() -> f64;

  /// sqrt(2)
  /// @value 1.4142135623730951
  sqrt-n2: func() -> f64;

  /// The full circle constant (τ)
  /// @value 6.283185307179586
  tau: func() -> f64;

  /// Odd numbers. Stream closes when it reaches max int.
  /// @value [1]
  /// @expression |v| v + 2
  odd: async func() -> stream<u64>;

  /// Even numbers. Stream closes when it reaches max int.
  /// @value [0]
  /// @expression |v| v + 2
  even: async func() -> stream<u64>;

  /// Arithmetic sequence. Stream closes when it reaches max int.
  /// @expression || n + d * $i
  arithmetic: async func(n: u64, d: u64) -> stream<u64>;

  /// Geometric sequence. Stream closes when it reaches max int.
  /// @expression || n * r ** $i
  geometric: async func(n: u64, r: u64) -> stream<u64>;

  /// Fibonacci sequence. Stream closes when it reaches max int.
  /// @value [1, 1]
  /// @expression |a, b| a + b
  fibonacci: async func() -> stream<u64>;

  /// Factorial sequence. Stream closes when it reaches max int.
  /// @value [1, 1]
  /// @expression |v| v * $i
  factorial: async func() -> stream<u64>;

  /// Harmonic sequence. Stream closes when it reaches min-positive.
  /// @expression || n / ($i + 1) as f64
  harmonic: async func(n: f64) -> stream<f64>;

  /// Figurate sequence. Stream closes when it reaches max int.
  /// @expression || $i ** n
  figurate: async func(n: u64) -> stream<u64>;

  /// Prime numbers, each found by trial division from the previous one.
  /// Stream closes when it reaches max int.
  /// @value [2]
  /// @expression |v| {
  ///     let mut n = v + 1;
  ///     let mut d: u64 = 2;
  ///     while d * d <= n {
  ///         if n % d == 0 {
  ///             n += 1;
  ///             d = 2;
  ///         } else {
  ///             d += 1;
  ///         }
  ///     }
  ///     n
  /// }
  prime: async func() -> stream<u64>;
}