From f1d2f8d53d08943ec39bfe21c4c51ec3973e0dae Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 28 Feb 2020 20:04:02 +0100 Subject: [PATCH] added polynomial for sine approximation --- STATUS.md | 2 +- c64/basic/,stubs_math/e26b.sin_FAC1.s | 11 +++++++++++ tools/generate_constants.cc | 10 ++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/STATUS.md b/STATUS.md index b568ba51..ad5d7e75 100644 --- a/STATUS.md +++ b/STATUS.md @@ -239,7 +239,7 @@ Floating point mathematical routines - not official, but well known and broadly | `$E09A` | `rnd_A` | DONE | | | `$E0BE` | `rnd_generate` | DONE | | | `$E264` | `cos_FAC1` | NOT DONE | | -| `$E26B` | `sin_FAC1` | NOT DONE | | +| `$E26B` | `sin_FAC1` | NOT DONE | some work already started | | `$E2B4` | `tan_FAC1` | NOT DONE | | | `$E30E` | `atn_FAC1` | NOT DONE | | diff --git a/c64/basic/,stubs_math/e26b.sin_FAC1.s b/c64/basic/,stubs_math/e26b.sin_FAC1.s index 99eb4569..82a86d2f 100644 --- a/c64/basic/,stubs_math/e26b.sin_FAC1.s +++ b/c64/basic/,stubs_math/e26b.sin_FAC1.s @@ -15,3 +15,14 @@ sin_FAC1: STUB_IMPLEMENTATION() + +poly_sin: + + .byte $05 // series length - 1 + + put_const_POLY_SIN_1() + put_const_POLY_SIN_2() + put_const_POLY_SIN_3() + put_const_POLY_SIN_4() + put_const_POLY_SIN_5() + put_const_POLY_SIN_6() diff --git a/tools/generate_constants.cc b/tools/generate_constants.cc index 6d27caed..5e40b233 100644 --- a/tools/generate_constants.cc +++ b/tools/generate_constants.cc @@ -57,6 +57,16 @@ std::vector GLOBAL_constants = ConstEntry( "INV_SQR_2", 1.0 / std::sqrt(2.0) ), ConstEntry( "LOG_2", std::log(2.0) ), ConstEntry( "INV_LOG_2", 1.0 / std::log(2.0) ), + + // Constants for sine approximation, minimized abs. error, degree 11, from: + // - https://publik-void.github.io/sin-cos-approximations/ + + ConstEntry( "POLY_SIN_1", -2.3794713545277060334805162803882547e-8 ), + ConstEntry( "POLY_SIN_2", 2.75188556386854406868696924998396177e-6 ), + ConstEntry( "POLY_SIN_3", -0.000198407028626057951892931706291369095 ), + ConstEntry( "POLY_SIN_4", 0.00833332926445715285723741015926085083 ), + ConstEntry( "POLY_SIN_5", -0.166666665414391662957238076832950332 ), + ConstEntry( "POLY_SIN_6", 0.99999999988985190065414932682350994 ), }; //