acme/examples/trigono.a
2013-04-07 21:29:09 +00:00

38 lines
1.1 KiB
Plaintext

;ACME 0.93
!to "trigono.o", plain
* = $c000
PI = 3.14159265358979323846
!raw "cos[0,pi/2] scaled to 0-255 range"
!align $f, 0, 0 ; make output file look better in hex editor :)
!for x, 256 {
!byte cos(float(x - 1) / 255 * PI/2) * 255 + 0.5
}
; "x-1" converts interval [1,256] to interval [0,255]
; "float()" makes sure this calculation is done in float mode now
; "/255*half_PI" converts interval [0,255] to interval [0,PI/2]
; "cos()" returns cosine. Wow.
; "*255" converts interval [0,1] to interval [0,255]
; "+0.5" ensures correct rounding to integer
!align $f, 0, 0
!raw "sin[-pi/2,pi/2] scaled to full range of 16b.16b fixed point"
!align $f, 0, 0
!for x, 1024 {
!32 sin(float(x - 513) / 1024 * PI) * 65536 + 0.5
}
;undefined = 0.0 / 0.0 ; throws error when active
;range = arcsin(-10) ; throws error when active
!by 1 / 2 * 2 ; should give 0
!by 1 / 2 * 2.0 ; should give 0
!by 1 / 2.0 * 2 ; should give 1
!by 1 / 2.0 * 2.0 ; should give 1
!by 1.0 / 2 * 2 ; should give 1
!by 1.0 / 2 * 2.0 ; should give 1
!by 1.0 / 2.0 * 2 ; should give 1
!by 1.0 / 2.0 * 2.0 ; should give 1