Skip to content

Commit 1dabcb8

Browse files
Make 2^3 = 8
1 parent ea63425 commit 1dabcb8

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

fp.s

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
; D and E are used by the string conversion functions.
2020

2121
BIAS = 128
22-
MAXDIGITS = 10
2322

2423
.bss
2524

@@ -41,7 +40,7 @@ fp_ten: .byte $00, $00, $00, $20, 131
4140
fp_string_max: .byte $00, $28, $6B, $6E, 157 ; 10^9 (1,000,000,000)
4241
fp_string_min: .byte $00, $20, $BC, $3E, 154 ; 10^8 (100,000,000)
4342
fp_log_2: .byte $F8, $17, $72, $31, 127
44-
fp_sqrt_2: .byte $33, $F3, $04, $35, 128
43+
fp_sqrt_2: .byte $34, $F3, $04, $35, 128
4544
fp_pi: .byte $81, $CF, $0F, $49, 129
4645

4746
; Loads a new Float value from memory into FP0 or FP1.
@@ -1402,7 +1401,9 @@ flog_x_plus_1 = fp_scratch + .sizeof(Float) * 3
14021401
flog_k = fp_scratch + .sizeof(Float) * 4
14031402

14041403
fp_log_coefficients:
1405-
.byte $E3, $38, $8E, $63, 124 ; 1/9 x^9 / 9
1404+
.byte $9E, $D8, $89, $1D, 124 ; 1/13 x^13 / 13
1405+
.byte $A3, $8B, $2E, $3A, 124 ; 1/11 + x^11 / 11
1406+
.byte $E3, $38, $8E, $63, 124 ; 1/9 + x^9 / 9
14061407
.byte $92, $24, $49, $12, 125 ; 1/7 + x^7 / 7
14071408
.byte $CD, $CC, $CC, $4C, 125 ; 1/5 + x^5 / 5
14081409
.byte $AA, $AA, $AA, $2A, 126 ; 1/3 + x^3 / 3
@@ -1458,7 +1459,7 @@ flog:
14581459
lday #flog_x_plus_1 ; Calculate (arg - 1) / (arg + 1)
14591460
jsr fdiv
14601461
ldax #fp_log_coefficients
1461-
ldy #5
1462+
ldy #7
14621463
jsr fpoly_odd
14631464
inc FP0e ; Increment the exponent to multiply by 2
14641465
lday #flog_k ; Add in the log of the exponent

tests/fp_test.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,12 @@ const OperationTestCase fdiv_test_cases[] = {
469469
TEST_OPERATION(fdiv);
470470

471471
const OperationTestCase fpow_test_cases[] = {
472-
// 1 ^ 1
473-
{ { 0x00000000, 128 }, { 0x00000000, 128 }, { 0x00000001, 128 } },
474-
// 2 ^ 1
475-
{ { 0x00000000, 129 }, { 0x00000000, 128 }, { 0x00000002, 129 } },
476-
// 2 ^ 2
477-
{ { 0x00000000, 129 }, { 0x00000000, 129 }, { 0x00000004, 130 } },
472+
// 1 ^ 1 = 1.0 (exact)
473+
{ { 0x00000000, 128 }, { 0x00000000, 128 }, { 0x00000000, 128 } },
474+
// 2 ^ 1 = 2.0 (exact)
475+
{ { 0x00000000, 129 }, { 0x00000000, 128 }, { 0x00000000, 129 } },
476+
// 2 ^ 2 = 4.0 (exact)
477+
{ { 0x00000000, 129 }, { 0x00000000, 129 }, { 0x00000000, 130 } },
478478
};
479479

480480
TEST_OPERATION(fpow);
@@ -819,12 +819,12 @@ void test_function(const char* f_name, void (*f)(void), const FunctionTestCase*
819819
}
820820

821821
const FunctionTestCase flog_test_cases[] = {
822-
// log(1.0) = 0.0
823-
{ { 0x00000000, 128 }, { 0x20000000, 97 } },
824-
// log(0.5) = -0.6931471805599453
825-
{ { 0x00000000, 127 }, { 0xB17217F6, 127 } },
826-
// log(2) = 0.693147181
827-
{ { 0x00000000, 129 }, { 0x317217FC, 127 } },
822+
// log(1.0) = 0.0 exactly
823+
{ { 0x00000000, 128 }, { 0x00000000, 0 } },
824+
// log(0.5) = -0.6931471805599453 (within 0.18 ULPs of true)
825+
{ { 0x00000000, 127 }, { 0xB17217F8, 127 } },
826+
// log(2) = 0.693147180559945 (= fp_log_2, maximally accurate)
827+
{ { 0x00000000, 129 }, { 0x317217F8, 127 } },
828828
};
829829

830830
TEST_FUNCTION(flog);

0 commit comments

Comments
 (0)