diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-10-31 13:46:11 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-10-31 21:13:19 +0100 |
| commit | 4aa2b717f9e050783b567540d9bb0193d692e3e9 (patch) | |
| tree | 39b3734c464655e6d1c21390945209a66f952654 /doc | |
| parent | e0bf13622b0922252439e3fa8b43df9877678d75 (diff) | |
support floating point numbers
* Extends the SciTECO type system. A number on the expression stack
or in a Q-register can be either an integer or a float.
* Floating point constants begin with a digit (like all other
numbers), are followed by a `.` and an optional fractional part.
Exponents cannot currently be written.
E.g. `1.` == `1.0`. But `.0` would still be `.,0`.
(!) To push an integer followed by dot, you must now write e.g. `1,.` or `1 .`.
* All of the basic arithmetic operators operate like this:
If both operands are integers, the result is also an integer (integer arithmetics).
If at least one of the operands is a float, the result is also a float (float arithmetics).
* All of the binary operators (AND, OR, XOR) always cast all
operands to integer and the result is always an integer as well.
* You can "cast" integers to float by `*1.` or `/1.`.
You can "cast" floats to integers using `#0`.
* Most commands still accept only integers. Floats are implicitly casted to integers.
Float-aware commands are: =, \, ^W, Qq, Uq, %q and the conditionals.
* `%q` will not change the current type of register q.
* Numeric part of "lexer.font" is now a float (in points).
* You cannot currently print octal and hexadecimal floats.
`==` and `===` are identical to `=` on floats.
* `===` is now printing hex integers in lower case.
This is because SciTECO's coding style for hex constants is also lower case.
* `--with-teco-integer` renamed to `--with-teco-number`.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/sciteco.7.template | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/doc/sciteco.7.template b/doc/sciteco.7.template index fd909f9..b6b0795 100644 --- a/doc/sciteco.7.template +++ b/doc/sciteco.7.template @@ -999,9 +999,9 @@ two prefix arguments and returning at most one value for the next command into a much more elaborate scheme where commands accept .I n arguments and return -.I n +.I m arguments. -This is done using an integer value stack. +This is done using a number value stack. The stack is used for passing arguments and for arithmetics. \*(ST is thus a stack-based language. Nevertheless unary prefix and binary infix operators including operator @@ -1009,11 +1009,25 @@ preference are supported. Since the same stack is used for arithmetics and command arguments, arithmetics and arbitrary code may be freely mixed like in expression-centered languages and some classic TECOs. -For the sake of macro portability all integers are 64-bit signed -integers regardless of the host's architecture. -The integer storage size may be changed at \*(ST build time +For the sake of macro portability all numbers are 64-bit wide +regardless of the host's architecture. +The number storage size may be changed at \*(ST build time however. -In this specific build, integers are @TECO_INTEGER@-bit. +In this specific build, numbers are @TECO_NUMBER@-bit. +.LP +.SCITECO_TOPIC integer float +A \*(ST number can be either a signed integer or floating point +number \(em it is dynamically typed. +Integer constants create integers and floating point constants +create floats. +Operators create integers if all operands are integers, +while a single float operand has a float result as well. +As an exception, the binary operators (AND, OR, XOR) +will always cast float operands to integers discarding the fractional +part of the number. +If a command takes only integer arguments, as is currently the +case for all commands accepting buffer positions and line counts, +float arguments will be automatically casted to integers. .LP .SCITECO_TOPIC bool boolean Some commands expect or return booleans, most often signifying @@ -1031,7 +1045,7 @@ command. .SS Constants .SCITECO_TOPIC constants decimal octal hexadecimal . -All integer constants have to begin with a digit from 0 to 9. +All number constants have to begin with a digit from 0 to 9. Constants beginning with 0 are octal constants where every digit represents 3 bits \(em similar to C (e.g. \(lq033\(rq is decimal 27). Digits 8 and 9 are not allowed in octal constants. @@ -1052,7 +1066,19 @@ decimal. Digits larger than or equal to the current radix are not allowed in constants. .LP -A complete constant is pushed on the number stack. +A \(lq.\(rq in a number constant separates the integer and fractional +parts of a floating point number. +The integer part is always required, while the fractional part is optional. +\(lq1.\(rq is therefore equivalent to \(lq1.0\(rq and does \fBnot\fP +push 1 and the current buffer position (dot) to the stack \(em you can +insert explicit commas if you would like to do that (\(lq1,.\(rq). +Floating point constants cannot currently contain exponents. +Floating point constants beginning with \(lq0.\(rq are not octal. +\# But ^O0.333 would be. You can also write e.g. @0ff.ff for hexadecimal +\# floating point constants. But this is pretty useless to my knowledge. +.LP +A complete constant is pushed on the number stack, either as an integer +or float. \# Mention the minus operator? \# It's not technically part of the number syntax. Since whitespace characters will also terminate integer constants @@ -1068,10 +1094,14 @@ precedence: .SCITECO_TT 90n .TS box,tab(;); -L LX. +L | LX | L. +Operator;Description;Types +_ \fIbase\fB ^* \fIpower\fR;T{ .SCITECO_TOPIC ^* power Raise \fIbase\fP to \fIpower\fP. +T};T{ +integers and floats T} = \fIa\fB ^/ \fIb\fR;T{ @@ -1079,40 +1109,42 @@ T} Remainder of \fIa\fP divided by \fIb\fP. It is actually a modulo operation conforming to the host C compiler's modulo semantics. -T} +T};\^ \fIa\fB / \fIb\fR;T{ .SCITECO_TOPIC / divide slash Divide \fIa\fP by \fIb\fP. Naturally it is a division without remainder. -T} +T};\^ \fIa\fB * \fIb\fP;T{ .SCITECO_TOPIC * multiply asterisk Multiply \fIa\fP by \fIb\fP. -T} +T};\^ = \fIa\fB - \fIb\fP;T{ .SCITECO_TOPIC - subtract minus Subtract \fIb\fP from \fIa\fP. -T} +T};\^ \fIa\fB + \fIb\fP;T{ .SCITECO_TOPIC + add plus Add \fIb\fP to \fIa\fP. -T} +T};\^ = \fIa\fB & \fIb\fP;T{ .SCITECO_TOPIC & and ampersand Binary AND. +T};T{ +integers T} = \fIa\fB ^# \fIb\fP;T{ .SCITECO_TOPIC ^# xor Binary exclusive OR (XOR). -T} +T};\^ = \fIa\fB # \fIb\fP;T{ .SCITECO_TOPIC # or hash Binary OR. -T} +T};\^ .TE .SCITECO_TT_END SP .LP @@ -1508,8 +1540,10 @@ it toggles the order of word vs. non-word characters that are skipped or deleted .SCITECO_TOPIC Q-Register . \*(ST may store data in so called Q-Registers. -Each Q-Register cell has an integer and string part (can store +Each Q-Register cell has a number and string part (can store both at the same time). +A number is either an integer or a floating point number (only +one at a time). Strings are actually Scintilla documents. Therefore Q-Register strings may be edited just like buffers (see \fBEQ\fP command). |
