1
0
mirror of https://github.com/janet-lang/janet synced 2025-08-04 13:03:52 +00:00

Update documentation to remove references of integers and real numbers.

Now there is only one kind of number.
This commit is contained in:
Calvin Rose 2018-12-27 13:13:02 -05:00
parent 6b95326d7c
commit 59f6c335ad
3 changed files with 15 additions and 39 deletions

View File

@ -44,18 +44,8 @@ prefix notation. Janet also supports the remainder operator, or `%`, which retur
the remainder of division. For example, `(% 10 3)` is 1, and `(% 10.5 3)` is the remainder of division. For example, `(% 10 3)` is 1, and `(% 10.5 3)` is
1.5. The lines that begin with `#` are comments. 1.5. The lines that begin with `#` are comments.
Janet actually has two "flavors" of numbers; integers and real numbers. Integers are any All janet numbers are IEEE 754 floating point numbers. They can be used to represent
integer value between -2,147,483,648 and 2,147,483,647 (32 bit signed integer). both integers and real numbers to a finite precision.
Reals are real numbers, and are represented by IEEE-754 double precision floating point
numbers. That means that they can represent any number an integer can represent, as well
fractions to very high precision.
Although real numbers can represent any value an integer can, try to distinguish between
real numbers and integers in your program. If you are using a number to index into a structure,
you probably want integers. Otherwise, you may want to use reals (this is only a rule of thumb).
Arithmetic operator will convert integers to real numbers if needed, but real numbers
will not be converted to integers, as not all real numbers can be safely converted to integers.
## Numeric literals ## Numeric literals

View File

@ -70,8 +70,8 @@ in macros.
## Numbers ## Numbers
Janet numbers are represented by either 32 bit integers or Janet numbers are represented by IEEE-754 floating point numbers.
IEEE-754 floating point numbers. The syntax is similar to that of many other languages The syntax is similar to that of many other languages
as well. Numbers can be written in base 10, with as well. Numbers can be written in base 10, with
underscores used to separate digits into groups. A decimal point can be used for floating underscores used to separate digits into groups. A decimal point can be used for floating
point numbers. Numbers can also be written in other bases by prefixing the number with the desired point numbers. Numbers can also be written in other bases by prefixing the number with the desired

View File

@ -153,40 +153,30 @@ failure to return or error.
* The `>>>` indicates unsigned right shift, as in Java. Because all integers in janet are * The `>>>` indicates unsigned right shift, as in Java. Because all integers in janet are
signed, we differentiate the two kinds of right bit shift. signed, we differentiate the two kinds of right bit shift.
* The 'im' suffix in the instruction name is short for immediate. The 'i' suffix is short for integer, * The 'im' suffix in the instruction name is short for immediate.
and the 'r' suffix is short for real.
### Reference Table ### Reference Table
| Instruction | Signature | Description | | Instruction | Signature | Description |
| ----------- | --------------------------- | --------------------------------- | | ----------- | --------------------------- | --------------------------------- |
| `add` | `(add dest lhs rhs)` | $dest = $lhs + $rhs | | `add` | `(add dest lhs rhs)` | $dest = $lhs + $rhs |
| `addi` | `(addi dest lhs rhs)` | $dest = $lhs +i $rhs | | `addim` | `(addim dest lhs im)` | $dest = $lhs + im |
| `addim` | `(addim dest lhs im)` | $dest = $lhs +i im |
| `addr` | `(addr dest lhs rhs)` | $dest = $lhs +r $rhs |
| `band` | `(band dest lhs rhs)` | $dest = $lhs & $rhs | | `band` | `(band dest lhs rhs)` | $dest = $lhs & $rhs |
| `bnot` | `(bnot dest operand)` | $dest = ~$operand | | `bnot` | `(bnot dest operand)` | $dest = ~$operand |
| `bor` | `(bor dest lhs rhs)` | $dest = $lhs | $rhs | | `bor` | `(bor dest lhs rhs)` | $dest = $lhs | $rhs |
| `bxor` | `(bxor dest lhs rhs)` | $dest = $lhs ^ $rhs | | `bxor` | `(bxor dest lhs rhs)` | $dest = $lhs ^ $rhs |
| `call` | `(call dest callee)` | $dest = call($callee, args) | | `call` | `(call dest callee)` | $dest = call($callee, args) |
| `clo` | `(clo dest index)` | $dest = closure(defs[$index]) | | `clo` | `(clo dest index)` | $dest = closure(defs[$index]) |
| `cmp` | `(cmp dest lhs rhs)` | $dest = janet\_compare($lhs, $rhs) | | `cmp` | `(cmp dest lhs rhs)` | $dest = janet\_compare($lhs, $rhs)|
| `div` | `(div dest lhs rhs)` | $dest = $lhs / $rhs | | `div` | `(div dest lhs rhs)` | $dest = $lhs / $rhs |
| `divi` | `(divi dest lhs rhs)` | $dest = $lhs /i $rhs | | `divim` | `(divim dest lhs im)` | $dest = $lhs / im |
| `divim` | `(divim dest lhs im)` | $dest = $lhs /i im |
| `divr` | `(divr dest lhs rhs)` | $dest = $lhs /r $rhs |
| `eq` | `(eq dest lhs rhs)` | $dest = $lhs == $rhs | | `eq` | `(eq dest lhs rhs)` | $dest = $lhs == $rhs |
| `eqi` | `(eqi dest lhs rhs)` | $dest = $lhs ==i $rhs | | `eqim` | `(eqim dest lhs im)` | $dest = $lhs == im |
| `eqim` | `(eqim dest lhs im)` | $dest = $lhs ==i im |
| `eqr` | `(eqr dest lhs rhs)` | $dest = $lhs ==r $rhs |
| `err` | `(err message)` | Throw error $message. | | `err` | `(err message)` | Throw error $message. |
| `get` | `(get dest ds key)` | $dest = $ds[$key] | | `get` | `(get dest ds key)` | $dest = $ds[$key] |
| `geti` | `(geti dest ds index)` | $dest = $ds[index] | | `geti` | `(geti dest ds index)` | $dest = $ds[index] |
| `gt` | `(gt dest lhs rhs)` | $dest = $lhs > $rhs | | `gt` | `(gt dest lhs rhs)` | $dest = $lhs \> $rhs |
| `gti` | `(gti dest lhs rhs)` | $dest = $lhs \>i $rhs | | `gtim` | `(gtim dest lhs im)` | $dest = $lhs \> im |
| `gtim` | `(gtim dest lhs im)` | $dest = $lhs \>i im |
| `gtr` | `(gtr dest lhs rhs)` | $dest = $lhs \>r $rhs |
| `gter` | `(gter dest lhs rhs)` | $dest = $lhs >=r $rhs |
| `jmp` | `(jmp label)` | pc = label, pc += offset | | `jmp` | `(jmp label)` | pc = label, pc += offset |
| `jmpif` | `(jmpif cond label)` | if $cond pc = label else pc++ | | `jmpif` | `(jmpif cond label)` | if $cond pc = label else pc++ |
| `jmpno` | `(jmpno cond label)` | if $cond pc++ else pc = label | | `jmpno` | `(jmpno cond label)` | if $cond pc++ else pc = label |
@ -198,10 +188,8 @@ failure to return or error.
| `ldt` | `(ldt dest)` | $dest = true | | `ldt` | `(ldt dest)` | $dest = true |
| `ldu` | `(ldu dest env index)` | $dest = envs[env][index] | | `ldu` | `(ldu dest env index)` | $dest = envs[env][index] |
| `len` | `(len dest ds)` | $dest = length(ds) | | `len` | `(len dest ds)` | $dest = length(ds) |
| `lt` | `(lt dest lhs rhs)` | $dest = $lhs < $rhs | | `lt` | `(lt dest lhs rhs)` | $dest = $lhs \< $rhs |
| `lti` | `(lti dest lhs rhs)` | $dest = $lhs \<i $rhs | | `ltim` | `(ltim dest lhs im)` | $dest = $lhs \< im |
| `ltim` | `(ltim dest lhs im)` | $dest = $lhs \<i im |
| `ltr` | `(ltr dest lhs rhs)` | $dest = $lhs \<r $rhs |
| `mkarr` | `(mkarr dest)` | $dest = call(array, args) | | `mkarr` | `(mkarr dest)` | $dest = call(array, args) |
| `mkbuf` | `(mkbuf dest)` | $dest = call(buffer, args) | | `mkbuf` | `(mkbuf dest)` | $dest = call(buffer, args) |
| `mktab` | `(mktab dest)` | $dest = call(table, args) | | `mktab` | `(mktab dest)` | $dest = call(table, args) |
@ -210,10 +198,8 @@ failure to return or error.
| `mktup` | `(mktup dest)` | $dest = call(tuple, args) | | `mktup` | `(mktup dest)` | $dest = call(tuple, args) |
| `movf` | `(movf src dest)` | $dest = $src | | `movf` | `(movf src dest)` | $dest = $src |
| `movn` | `(movn dest src)` | $dest = $src | | `movn` | `(movn dest src)` | $dest = $src |
| `mul` | `(mul dest lhs rhs)` | $dest = $lhs * $rhs | | `mul` | `(mul dest lhs rhs)` | $dest = $lhs \* $rhs |
| `muli` | `(muli dest lhs rhs)` | $dest = $lhs \*i $rhs | | `mulim` | `(mulim dest lhs im)` | $dest = $lhs \* im |
| `mulim` | `(mulim dest lhs im)` | $dest = $lhs \*i im |
| `mulr` | `(mulr dest lhs rhs)` | $dest = $lhs \*r $rhs |
| `noop` | `(noop)` | Does nothing. | | `noop` | `(noop)` | Does nothing. |
| `push` | `(push val)` | Push $val on arg | | `push` | `(push val)` | Push $val on arg |
| `push2` | `(push2 val1 val3)` | Push $val1, $val2 on args | | `push2` | `(push2 val1 val3)` | Push $val1, $val2 on args |