OK, my idea that long multiplication is like long addition is wrong.

It's still broken, but it's broken because of fundamental misunderstanding which tinkering won't solve.
This commit is contained in:
Simon Brooke 2019-01-20 23:34:46 +00:00
parent 22fa7314d6
commit 64fc43e9fc
6 changed files with 56 additions and 14 deletions

View file

@ -27,6 +27,7 @@
#include "conspage.h"
#include "consspaceobject.h"
#include "debug.h"
#include "lispops.h"
/*
* The maximum value we will allow in an integer cell.
@ -104,14 +105,20 @@ struct cons_pointer make_integer( int64_t value, struct cons_pointer more ) {
* \see operate_on_integers
*/
__int128_t cell_value( struct cons_pointer c, char op, bool is_first_cell ) {
long int val = nilp( c ) ? 0 : pointer2cell( c ).payload.integer.value;
long int val = nilp( c ) ?
0 :
pointer2cell( c ).payload.integer.value;
long int carry = is_first_cell ? 0 : ( MAX_INTEGER + 1 );
__int128_t result = ( __int128_t ) integerp( c ) ?
( val == 0 ) ? carry : val : op == '*' ? 1 : 0;
( val == 0 ) ?
carry :
val :
0;
debug_printf( DEBUG_ARITH,
L"cell_value: raw value is %ld, op = '%c', is_first_cell = %s; returning ",
val, op, is_first_cell ? "true" : "false" );
L"cell_value: raw value is %ld, op = '%c', is_first_cell = %s; %4.4s; returning ",
val, op, is_first_cell ? "true" : "false", pointer2cell(c).tag.bytes);
debug_print_128bit( result, DEBUG_ARITH );
debug_println( DEBUG_ARITH );
@ -139,6 +146,7 @@ struct cons_pointer operate_on_integers( struct cons_pointer a,
struct cons_pointer b, char op ) {
struct cons_pointer result = NIL;
struct cons_pointer cursor = NIL;
__int128_t carry = 0;
bool is_first_cell = true;
@ -163,7 +171,7 @@ struct cons_pointer operate_on_integers( struct cons_pointer a,
switch ( op ) {
case '*':
rv = av * ( bv + carry );
rv = (av * bv) + carry;
break;
case '+':
rv = av + bv + carry;