From abd67c40f9ca3389247bfb72feb11701a190e4cf Mon Sep 17 00:00:00 2001 From: Rikard Nordgren Date: Fri, 10 Apr 2026 20:32:55 +0200 Subject: [PATCH] Add floating point constants for FOUT --- src/basic/math_consts/bdb3.consts_FOUT.s | 24 ++++++++++++++++++++++++ tools/generate_constants.cc | 5 +++++ tools/similarity.c | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/basic/math_consts/bdb3.consts_FOUT.s diff --git a/src/basic/math_consts/bdb3.consts_FOUT.s b/src/basic/math_consts/bdb3.consts_FOUT.s new file mode 100644 index 00000000..32433be6 --- /dev/null +++ b/src/basic/math_consts/bdb3.consts_FOUT.s @@ -0,0 +1,24 @@ +;; #LAYOUT# STD * #TAKE +;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000 +;; #LAYOUT# * BASIC_0 #TAKE +;; #LAYOUT# * * #IGNORE + +; This file is under the MIT license, it contains code released by Microsoft Corporation. +; See LICENSE for more information. + +; Math package - constants used by FOUT +; +; This is verified to be identical to the original Microsoft implementation +; + +const_NZ0999: + + +PUT_CONST_NZ0999 + +const_NZ9999: + + +PUT_CONST_NZ9999 + +const_NZMIL: + + +PUT_CONST_NZMIL diff --git a/tools/generate_constants.cc b/tools/generate_constants.cc index 2f3c2cd7..a3023eef 100644 --- a/tools/generate_constants.cc +++ b/tools/generate_constants.cc @@ -58,6 +58,11 @@ std::vector GLOBAL_constants = ConstEntry( "LOG_2", std::log(2.0) ), ConstEntry( "INV_LOG_2", 1.0 / std::log(2.0) ), + // Constants for FOUT + ConstEntry( "NZ0999", 99999999.9 ), // Comment in MS-BASIC says 99999999.9499, but that is off by one ulp + ConstEntry( "NZ9999", 999999999.2 ), // Comment is MS-BASIC says 999999999.499, but that is off by one ulp + ConstEntry( "NZMIL", 1e9 ), + // Constants for exp approximation, taken from https://www.c64-wiki.com/wiki/POLY1 // original source is probably "Computer Approximations" by John Fraser Hart et al. (ISBN 0-88275-642-7) ConstEntry( "POLY_EXP_1", 2.1498763701e-5 ), diff --git a/tools/similarity.c b/tools/similarity.c index fe1a7e05..18c19f33 100644 --- a/tools/similarity.c +++ b/tools/similarity.c @@ -20,7 +20,7 @@ int matches[MAX_SIZE]; int phase_mask[MAX_SIZE+MAX_SIZE]; -#define NUM_CHUNKS 8 +#define NUM_CHUNKS 9 // Pairs of start, end memory addresses of known exact similarity with the open source Microsoft BASIC unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { 0xB391, 0xB39D, @@ -29,6 +29,7 @@ unsigned short microsoft_basic_chunks[NUM_CHUNKS * 2] = { 0xB983, 0xB9BB, 0xBA28, 0xBCF2, 0xBD7E, 0xBD90, + 0xBDB3, 0xBDC1, 0xBF11, 0xBF51, 0xBFB4, 0xBFBE, };