Redefine the trig functions to divide circles into 1.0 turns (#1060)

This makes their behavior consistent across Q settings

Fixes #1059
This commit is contained in:
Rangi
2022-09-29 04:57:29 -04:00
committed by GitHub
parent 3567faf395
commit 023884d2b0
6 changed files with 72 additions and 35 deletions

View File

@@ -57,8 +57,8 @@ and ending with
.Ql */ .
It can be split across multiple lines, or occur in the middle of an expression:
.Bd -literal -offset indent
X = /* the value of x
should be 3 */ 3
DEF X = /* the value of x
should be 3 */ 3
.Ed
.Pp
Sometimes lines can be too long and it may be necessary to split them.
@@ -168,20 +168,20 @@ Valid print types are:
Examples:
.Bd -literal -offset indent
SECTION "Test", ROM0[2]
X: ;\ This works with labels **whose address is known**
Y = 3 ;\ This also works with variables
SUM equ X + Y ;\ And likewise with numeric constants
X: ;\ This works with labels **whose address is known**
DEF Y = 3 ;\ This also works with variables
DEF SUM EQU X + Y ;\ And likewise with numeric constants
; Prints "%0010 + $3 == 5"
PRINTLN "{#05b:X} + {#x:Y} == {d:SUM}"
rsset 32
PERCENT rb 1 ;\ Same with offset constants
VALUE = 20
RESULT = MUL(20.0, 0.32)
DEF PERCENT rb 1 ;\ Same with offset constants
DEF VALUE = 20
DEF RESULT = MUL(20.0, 0.32)
; Prints "32% of 20 = 6.40"
PRINTLN "{d:PERCENT}% of {d:VALUE} = {f:RESULT}"
WHO equs STRLWR("WORLD")
DEF WHO EQUS STRLWR("WORLD")
; Prints "Hello world!"
PRINTLN "Hello {s:WHO}!"
.Ed
@@ -350,18 +350,18 @@ The trigonometry functions (
.Ic SIN ,
.Ic COS ,
.Ic TAN ,
etc) are defined in terms of a circle divided into 65535.0 degrees.
etc) are defined in terms of a circle divided into 1.0 "turns" (equal to 2pi radians or 360 degrees).
.Pp
These functions are useful for automatic generation of various tables.
For example:
.Bd -literal -offset indent
; Generate a 256-byte sine table with values in the range [0, 128]
; (shifted and scaled from the range [-1.0, 1.0])
ANGLE = 0.0
REPT 256
db (MUL(64.0, SIN(ANGLE)) + 64.0) >> 16
ANGLE = ANGLE + 256.0 ; 256.0 = 65536 degrees / 256 entries
ENDR
; Generate a table of sine values from sin(0.0) to sin(1.0), with
; amplitude scaled from [-1.0, 1.0] to [0.0, 128.0]
DEF turns = 0.0
REPT 256
db MUL(64.0, SIN(turns) + 1.0) >> 16
DEF turns += 1.0 / 256
ENDR
.Ed
.Ss String expressions
The most basic string expression is any number of characters contained in double quotes
@@ -1011,7 +1011,7 @@ DEF ARRAY_SIZE EQU 4
DEF COUNT = 2
DEF COUNT = 3
DEF COUNT = ARRAY_SIZE + COUNT
COUNT = COUNT*2
DEF COUNT *= 2
;\ COUNT now has the value 14
.Ed
.Pp
@@ -1753,13 +1753,12 @@ You can also use
.Ic REPT
to generate tables on the fly:
.Bd -literal -offset indent
; Generate a 256-byte sine table with values in the range [0, 128]
; (shifted and scaled from the range [-1.0, 1.0])
ANGLE = 0.0
REPT 256
db (MUL(64.0, SIN(ANGLE)) + 64.0) >> 16
ANGLE = ANGLE + 256.0 ; 256.0 = 65536 degrees / 256 entries
ENDR
; Generate a table of square values from 0**2 = 0 to 100**2 = 10000
DEF x = 0
REPT 101
dw x * x
DEF x += 1
ENDR
.Ed
.Pp
As in macros, you can also use the escape sequence