diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-09 18:42:16 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-09 18:42:16 -0500 |
| commit | 1d461611bac782c272d0e082d5da74b4fe353ae6 (patch) | |
| tree | 0b1687a3edb507835f9aa3b7666fd590975b73ff /docs | |
| parent | 78fd9141bb7dfcf817158a7a4d098e0e4b3d515b (diff) | |
Rename Num -> Float64, Num32 -> Float32
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/functions.md | 2 | ||||
| -rw-r--r-- | docs/nums.md | 30 | ||||
| -rw-r--r-- | docs/optionals.md | 2 |
3 files changed, 17 insertions, 17 deletions
diff --git a/docs/functions.md b/docs/functions.md index 72279c11..b325ee9a 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -47,7 +47,7 @@ and are bound to arguments first, followed by binding positional arguments to any unbound arguments, in order: ```tomo -func foo(x:Int, y:Text, z:Num) +func foo(x:Int, y:Text, z:Float64) return "x=$x y=$y z=$z" >> foo(x=1, y="hi", z=2.5) diff --git a/docs/nums.md b/docs/nums.md index 1bd9b52d..911144ef 100644 --- a/docs/nums.md +++ b/docs/nums.md @@ -1,7 +1,7 @@ # Nums -Tomo has two floating point number types: `Num` (64-bit, AKA `double`) and -`Num32` (32-bit, AKA `float`). Num literals can have a decimal point (e.g. +Tomo has two floating point number types: `Float64` (64-bit, AKA `double`) and +`Float32` (32-bit, AKA `float`). Float64 literals can have a decimal point (e.g. `5.`), a scientific notation suffix (e.g. `1e8`) or a percent sign. Numbers that end in a percent sign are divided by 100 at compile time (i.e. `5% == 0.05`). Numbers can also use the `deg` suffix to represent degrees, which @@ -10,7 +10,7 @@ are converted to radians at compile time (i.e. `180deg == Nums.PI`). Nums support the standard math operations (`x+y`, `x-y`, `x*y`, `x/y`) as well as powers/exponentiation (`x^y`) and modulus (`x mod y` and `x mod1 y`). -32-bit numbers can be constructed using the type name: `Num32(123.456)`. +32-bit numbers can be constructed using the type name: `Float32(123.456)`. ## NaN @@ -26,11 +26,11 @@ differentiate between possibly-NaN values and definitely-not-NaN values. Tomo has a separate concept for expressing the lack of a defined value: optional types. Consequently, Tomo has merged these two concepts, so `NaN` is -called `none` and has the type `Num?` or `Num32?`. In this way, it's no +called `none` and has the type `Float64?` or `Float32?`. In this way, it's no different from optional integers or optional lists. This means that if a -variable has type `Num`, it is guaranteed to not hold a NaN value. This also +variable has type `Float64`, it is guaranteed to not hold a NaN value. This also means that operations which may produce NaN values have a result type of -`Num?`. For example, division can take two non-NaN values and return a result +`Float64?`. For example, division can take two non-NaN values and return a result that is NaN (zero divided by zero). Similarly, multiplication can produce NaN values (zero times infinity), and many math functions like `sqrt()` can return NaN for some inputs. @@ -42,36 +42,36 @@ required to be non-none. Here are a few examples: ```tomo >> x := 0.0 -= 0 : Num += 0 : Float64 y := 1.0 # Division might produce none: >> x / y -= 0 : Num? += 0 : Float64? >> x / x -= none : Num? += none : Float64? # Optional types and none values propagate: >> x/y + 1 + 2 -= 3 : Num? += 3 : Float64? >> x/x + 1 + 2 -= none : Num? += none : Float64? # Optional Nums can be handled explicitly using `or` and `!`: >> x/x or -123 -= -123 : Num += -123 : Float64 # This would raise a runtime error if `x` and `y` were zero: >> (x/y)! -= 0 : Num += 0 : Float64 # Assigning to a non-optional variable will do an implicit check for none and # raise a runtime error if the value is none, essentially the same as an # implicit `!`: x = x/y -func doop(x:Num -> Num) +func doop(x:Float64 -> Float64) # If a function's return type is non-optional and an optional value is # used in a return statement, an implicit none check will be inserted and # will error if the value is none: @@ -80,7 +80,7 @@ func doop(x:Num -> Num) # Function arguments are also implicitly checked for none if the given value # is optional and the function needs a non-optional value: >> doop(x/y) -= 0 : Num += 0 : Float64 ``` Hopefully the end result of this system is one where users can take advantage diff --git a/docs/optionals.md b/docs/optionals.md index 131daf19..6f2e3d5e 100644 --- a/docs/optionals.md +++ b/docs/optionals.md @@ -120,7 +120,7 @@ negative length for lists. However, for fixed-size integers (`Int64`, `Int32`, `Int16`, and `Int8`), bytes, and structs, an additional byte is required for out-of-band information about whether the value is none or not. -Floating point numbers (`Num` and `Num32`) use `NaN` to represent none, so +Floating point numbers (`Float64` and `Float32`) use `NaN` to represent none, so optional nums should be careful to avoid using `NaN` as a non-none value. This option was chosen to minimize the memory overhead of optional nums and because `NaN` literally means "not a number". |
