/all-integers-are-bignums: broken, but I don't know why.

This commit is contained in:
Simon Brooke 2018-12-30 11:10:14 +00:00
parent 489f008044
commit 61573d85d9
3 changed files with 19 additions and 6 deletions

View file

@ -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;
}

View file

@ -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 =

View file

@ -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: " );