From 61573d85d914f9b5c3797fa7809ff81201e9c3b8 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sun, 30 Dec 2018 11:10:14 +0000 Subject: [PATCH] /all-integers-are-bignums: broken, but I don't know why. --- src/arith/integer.c | 10 ++++++++++ src/arith/peano.c | 11 +++++------ src/memory/dump.c | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/arith/integer.c b/src/arith/integer.c index be50013..29e536e 100644 --- a/src/arith/integer.c +++ b/src/arith/integer.c @@ -125,6 +125,12 @@ struct cons_pointer multiply_integers( struct cons_pointer a, int64_t carry = 0; if ( integerp( a ) && integerp( b ) ) { + debug_print(L"multiply_integers: ", DEBUG_ARITH); + debug_print_object(a, DEBUG_ARITH); + debug_print(L" x ", DEBUG_ARITH); + debug_print_object(b, DEBUG_ARITH); + debug_println(DEBUG_ARITH); + while ( !nilp( a ) || !nilp( b ) || carry != 0 ) { int64_t av = integerp( a ) ? pointer2cell( a ).payload.integer.value : 1; @@ -134,6 +140,7 @@ struct cons_pointer multiply_integers( struct cons_pointer a, __int128_t rv = ( av * bv ) + carry; if ( rv > LONG_MAX || rv < LONG_MIN ) { + debug_printf( DEBUG_ARITH, L"multiply_integers: 64 bit overflow; setting carry to %ld\n", carry); carry = llabs( rv / LONG_MAX ); rv = rv % LONG_MAX; } else { @@ -145,6 +152,9 @@ struct cons_pointer multiply_integers( struct cons_pointer a, b = pointer2cell( b ).payload.integer.more; } } + debug_print(L"multiply_integers returning: ", DEBUG_ARITH); + debug_print_object(result, DEBUG_ARITH); + debug_println(DEBUG_ARITH); return result; } diff --git a/src/arith/peano.c b/src/arith/peano.c index 3fb732a..2a9fb7f 100644 --- a/src/arith/peano.c +++ b/src/arith/peano.c @@ -284,7 +284,8 @@ struct cons_pointer multiply_2( struct stack_frame *frame, result = arg2; break; case INTEGERTV: - result = multiply_integers( arg1, arg2 ); + result = make_integer(cell1.payload.integer.value * cell2.payload.integer.value, NIL); + //result = multiply_integers( arg1, arg2 ); break; case RATIOTV: result = @@ -411,9 +412,8 @@ struct cons_pointer inverse( struct cons_pointer frame, case RATIOTV: result = make_ratio( frame, make_integer( 0 - - to_long_int( cell.payload. - ratio.dividend ), - NIL ), + to_long_int( cell.payload.ratio. + dividend ), NIL ), cell.payload.ratio.divisor ); break; case REALTV: @@ -453,8 +453,7 @@ struct cons_pointer lisp_subtract( struct break; case INTEGERTV: result = make_integer( cell0.payload.integer.value - - cell1.payload.integer.value, - NIL ); + - cell1.payload.integer.value, NIL ); break; case RATIOTV:{ struct cons_pointer tmp = diff --git a/src/memory/dump.c b/src/memory/dump.c index 6601e92..24fd955 100644 --- a/src/memory/dump.c +++ b/src/memory/dump.c @@ -83,6 +83,10 @@ void dump_object( FILE * output, struct cons_pointer pointer ) { fwprintf( output, L"\t\tInteger cell: value %ld, count %u\n", cell.payload.integer.value, cell.count ); + if (!nilp(cell.payload.integer.more)) { + fputws( L"\t\tBIGNUM! More at\n:", output); + dump_object(output, cell.payload.integer.more); + } break; case LAMBDATV: fwprintf( output, L"\t\tLambda cell;\n\t\t args: " );