58 if ( divisor.
payload.integer.value == 1 ) {
61 int64_t ddrv = dividend.
payload.integer.value,
62 drrv = divisor.
payload.integer.value,
66 if ( drrv / gcd == 1 ) {
71 L
"simplify_ratio: %ld/%ld => %ld/%ld\n",
72 ddrv, drrv, ddrv / gcd, drrv / gcd );
108 cell2->
payload.ratio.divisor );
111 cell2->
payload.ratio.divisor ),
113 cell1->
payload.ratio.divisor ) );
117 ( L
"Shouldn't happen: bad arg to add_ratio_ratio" ),
157 ( L
"Shouldn't happen: bad arg to add_integer_ratio" ),
185 pointer2cell( arg2 ).payload.ratio.dividend,
false ), result =
226 ddrv = dd1v * dd2v, drrv = dr1v * dr2v;
230 result =
make_ratio( dividend, divisor,
true );
237 ( L
"Shouldn't happen: bad arg to multiply_ratio_ratio" ),
272 ( L
"Shouldn't happen: bad arg to multiply_integer_ratio" ),
327 cell->
payload.ratio.dividend = dividend;
328 cell->
payload.ratio.divisor = divisor;
332 if ( !
eq( result, unsimplified ) ) {
336 result = unsimplified;
341 ( L
"Dividend and divisor of a ratio must be integers" ),
365 cell_b->
payload.ratio.dividend ) &&
367 cell_b->
payload.ratio.divisor );
380 long double result = NAN;
395 ( (
long double ) dd_cell->
payload.integer.value ) /
396 ( (
long double ) dv_cell->
payload.integer.value );;
399 L
"real conversion is not yet implemented for bignums rationals." );
struct cons_pointer allocate_cell(uint32_t tag)
Allocates a cell with the specified tag.
#define ratiop(conspoint)
true if conspoint points to a rational number cell, else false
union cons_space_object::@3 payload
#define NIL
a cons pointer which points to the special NIL cell
#define RATIOTV
The string RTIO, considered as an unsigned int.
#define nilp(conspoint)
true if conspoint points to the special cell NIL, else false (there should only be one of these so it...
struct cons_pointer c_string_to_lisp_string(wchar_t *string)
Return a lisp string representation of this wide character string.
struct cons_pointer inc_ref(struct cons_pointer pointer)
increment the reference count of the object at this cons pointer.
struct cons_pointer dec_ref(struct cons_pointer pointer)
Decrement the reference count of the object at this cons pointer.
#define pointer2cell(pointer)
given a cons_pointer as argument, return the cell.
#define integerp(conspoint)
true if conspoint points to an integer cell, else false
struct cons_pointer make_cons(struct cons_pointer car, struct cons_pointer cdr)
Construct a cons cell from this pair of pointers.
An indirect pointer to a cons cell.
void debug_println(int level)
print a line feed to stderr, if verbosity matches level.
void debug_printf(int level, wchar_t *format,...)
wprintf adapted for the debug logging system.
void debug_print(wchar_t *message, int level)
print this debug message to stderr, if verbosity matches level.
void debug_print_object(struct cons_pointer pointer, int level)
print the object indicated by this pointer to stderr, if verbosity matches level.
#define DEBUG_ARITH
Print messages debugging arithmetic operations.
#define DEBUG_ALLOC
Print messages debugging memory allocation.
bool eq(struct cons_pointer a, struct cons_pointer b)
Shallow, and thus cheap, equality: true if these two objects are the same object, else false.
bool equal_integer_integer(struct cons_pointer a, struct cons_pointer b)
true if a and be are both integers whose value is the same value.
struct cons_pointer multiply_integers(struct cons_pointer a, struct cons_pointer b)
Return a pointer to an integer representing the product of the integers pointed to by a and b.
void release_integer(struct cons_pointer p)
if the value of p is less than the size of the small integer cache (and thus it was presumably suppli...
struct cons_pointer add_integers(struct cons_pointer a, struct cons_pointer b)
Return a pointer to an integer representing the sum of the integers pointed to by a and b.
struct cons_pointer acquire_integer(int64_t value, struct cons_pointer more)
Supply small valued integers from the small integer cache, if available.
struct cons_pointer throw_exception(struct cons_pointer message, struct cons_pointer frame_pointer)
Throw an exception.
struct cons_pointer negative(struct cons_pointer arg)
return a cons_pointer indicating a number which is the 0 - the number indicated by arg.
long double c_ratio_to_ld(struct cons_pointer rat)
convert a ratio to an equivalent long double.
int64_t greatest_common_divisor(int64_t m, int64_t n)
return, as an int64_t, the greatest common divisor of m and n,
struct cons_pointer add_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the sum of the ratios indicated by arg1 and arg2.
struct cons_pointer multiply_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the product of the ratios indicated by arg1 and ar...
bool equal_ratio_ratio(struct cons_pointer a, struct cons_pointer b)
True if a and be are identical rationals, else false.
struct cons_pointer divide_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer to a ratio which represents the value of the ratio indicated by arg1 divided by...
int64_t least_common_multiple(int64_t m, int64_t n)
return, as an int64_t, the least common multiple of m and n,
struct cons_pointer multiply_integer_ratio(struct cons_pointer intarg, struct cons_pointer ratarg)
return a cons_pointer indicating a number which is the product of the intger indicated by intarg and ...
struct cons_pointer add_integer_ratio(struct cons_pointer intarg, struct cons_pointer ratarg)
return a cons_pointer indicating a number which is the sum of the intger indicated by intarg and the ...
struct cons_pointer subtract_ratio_ratio(struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the difference of the ratios indicated by arg1 and...
struct cons_pointer make_ratio(struct cons_pointer dividend, struct cons_pointer divisor, bool simplify)
Construct a ratio frame from this dividend and divisor, expected to be integers, in the context of th...
struct cons_pointer simplify_ratio(struct cons_pointer pointer)
ratio.h