std/math

Phrases

math.Floor [x: number]

Round down

Gives
number
Contexts
node, main, check, look
Kind
phrase, native
Source
math/math.synod:3
Examples
math/rounding

math.Ceil [x: number]

Round up

Gives
number
Contexts
node, main, check, look
Kind
phrase, native
Source
math/math.synod:6
Examples
math/rounding

math.Min of [a: number] and [b: number]

Smaller

Gives
number
Contexts
node, main, check, look
Kind
phrase, native
Source
math/math.synod:9
Examples
math/rounding

math.Max of [a: number] and [b: number]

Larger

Gives
number
Contexts
node, main, check, look
Kind
phrase, native
Source
math/math.synod:12
Examples
math/rounding

math.Remainder of [a: number] by [b: number]

a − b × floor(a / b)

Gives
number
Contexts
node, main, check, look
Kind
phrase, native
Source
math/math.synod:15
Examples
math/rounding

math.Hash [t: text]

A fixed number in [0, 1) from the text: FNV-1a 64-bit over its UTF-8 bytes, mixed with the MurmurHash3 64-bit finalizer, then (h >> 11) / 2^53. Not random: it never touches the PRNG.

Gives
number
Contexts
node, main, check, look
Kind
phrase, native
Source
math/math.synod:18
Examples
math/hash

Examples

hash

Shows math.Hash: the same text always gives the same number in [0, 1), and it never uses the random seed

# package main
# Shows math.Hash: the same text always gives the same number in [0, 1), and it never uses the random seed
use std/lesson
use std/math
use std/sim
use std/text

define main
  lesson.Note (text.Join {"hash of key = ", (text.From (math.Hash "key"))})
  lesson.Note (text.Join {"again: ", (text.From (math.Hash "key"))})
  sim.StopAt 1s

rounding

Shows math.Floor, math.Ceil, math.Min, math.Max and math.Remainder on a few numbers

# package main
# Shows math.Floor, math.Ceil, math.Min, math.Max and math.Remainder on a few numbers
use std/lesson
use std/math
use std/sim
use std/text

define main
  lesson.Note (text.Join {"floor 2.7 = ", (text.From (math.Floor 2.7)), ", ceil 2.2 = ", (text.From (math.Ceil 2.2))})
  lesson.Note (text.Join {"min 4 9 = ", (text.From (math.Min of 4 and 9)), ", max 4 9 = ", (text.From (math.Max of 4 and 9))})
  lesson.Note (text.Join {"remainder of -1 by 5 = ", (text.From (math.Remainder of -1 by 5))})
  sim.StopAt 1s