Overview
Romasm's trigonometric functions use Taylor series expansions to calculate sine and cosine. These functions are located in stdlib/trig.romasm and stdlib/sine-taylor.romasm.
Note: All angles are in degrees and scaled by 100. Results are scaled by 1000.
Available Functions
sin
Calculates the sine of an angle using a 6-term Taylor series expansion.
sin(x) = x - x³/6 + x⁵/120 - x⁷/5040 + x⁹/362880 - x¹¹/39916800
| Input | Output |
|---|---|
| R0 = angle in degrees (scaled by 100) Example: 3000 = 30.00° |
R0 = sin(angle) × 1000 Example: ~500 for sin(30°) ≈ 0.5 |
LOAD R0, 3000 ; 30 degrees (scaled by 100)
CALL sin
PRINT R0 ; Outputs ~500 (0.5 × 1000)
Implementation: Uses argument reduction to handle angles > 90°, then applies Taylor series.
cos
Calculates the cosine of an angle. Uses the identity: cos(x) = sin(90° - x)
| Input | Output |
|---|---|
| R0 = angle in degrees (scaled by 100) | R0 = cos(angle) × 1000 |
LOAD R0, 0 ; 0 degrees
CALL cos
PRINT R0 ; Outputs ~1000 (1.0 × 1000)
sin_cordic
Simplified CORDIC (Coordinate Rotation Digital Computer) algorithm for sine. More efficient for hardware implementation.
Note: This is a simplified version. For full accuracy, use the sin function with Taylor series.
| Input | Output |
|---|---|
| R0 = angle in degrees (0-45°, scaled by 100) | R0 = sin(angle) × 1000 |
Scaling & Fixed-Point Arithmetic
Input Scaling
Angles are specified in degrees, scaled by 100:
3000= 30.00°4500= 45.00°9000= 90.00°
Output Scaling
Results are scaled by 1000:
1000= 1.0500= 0.5866≈ 0.866 (sin(60°))
Argument Reduction
For angles greater than 90°, the functions use argument reduction to map them to the 0-90° range where the Taylor series converges quickly.
How It Works
- Angles are reduced modulo 360°
- Angles > 90° use trigonometric identities:
- sin(180° - x) = sin(x)
- sin(180° + x) = -sin(x)
- sin(360° - x) = -sin(x)
Complete Example
; Calculate sin(30°) and cos(60°)
; sin(30°) = 0.5
; cos(60°) = 0.5
; Calculate sin(30°)
LOAD R0, 3000 ; 30 degrees (scaled by 100)
CALL sin
LOAD R1, R0 ; Save result in R1
PRINT R1 ; Outputs ~500
; Calculate cos(60°)
LOAD R0, 6000 ; 60 degrees (scaled by 100)
CALL cos
PRINT R0 ; Outputs ~500 (same as sin(30°))
Related Documentation
- Basic Math Functions - factorial, power, sqrt
- Calculus Functions - derivatives and integrals of trig functions
- Linker System - How to use stdlib functions