1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*-----------------------------------------------------------------*-C-*---
* File: handc/runtime/numsimpl.ci
*
* Copyright (C)1997 Donovan Kolbly <d.kolbly@rscheme.org>
* as part of the RScheme project, licensed for free use.
* See <http://www.rscheme.org/> for the latest information.
*
* File version: 1.2
* File mod date: 1997.11.29 23:10:53
* System build: v0.7.2, 97.12.21
*
*------------------------------------------------------------------------*/
obj basic_plus( obj x, obj y )
{
if (OBJ_ISA_FIXNUM(x))
{
if (OBJ_ISA_FIXNUM(y))
return FX_ADD(x,y);
else if (LONGFLOAT_P(y))
return make_float( fx2int(x) + extract_float(y) );
}
else if (LONGFLOAT_P(x))
{
if (OBJ_ISA_FIXNUM(y))
return make_float( extract_float(x) + fx2int(y) );
else if (LONGFLOAT_P(y))
return make_float( extract_float(x) + extract_float(y) );
}
scheme_error( "(base+ ~s ~s): argument not basic", 2, x, y );
return ZERO;
}
obj basic_minus( obj x, obj y )
{
if (OBJ_ISA_FIXNUM(x))
{
if (OBJ_ISA_FIXNUM(y))
return FX_SUB(x,y);
else if (LONGFLOAT_P(y))
return make_float( fx2int(x) - extract_float(y) );
}
else if (LONGFLOAT_P(x))
{
if (OBJ_ISA_FIXNUM(y))
return make_float( extract_float(x) - fx2int(y) );
else if (LONGFLOAT_P(y))
return make_float( extract_float(x) - extract_float(y) );
}
scheme_error( "(base- ~s ~s): argument not basic", 2, x, y );
return ZERO;
}
obj basic_mul( obj x, obj y )
{
if (OBJ_ISA_FIXNUM(x))
{
if (OBJ_ISA_FIXNUM(y))
return FX_MUL(x,y);
else if (LONGFLOAT_P(y))
return make_float( fx2int(x) * extract_float(y) );
}
else if (LONGFLOAT_P(x))
{
if (OBJ_ISA_FIXNUM(y))
return make_float( extract_float(x) * fx2int(y) );
else if (LONGFLOAT_P(y))
return make_float( extract_float(x) * extract_float(y) );
}
scheme_error( "(base* ~s ~s): argument not basic", 2, x, y );
return ZERO;
}
obj basic_div( obj x, obj y )
{
if (OBJ_ISA_FIXNUM(x))
{
if (OBJ_ISA_FIXNUM(y))
return make_float( (double)fx2int(x) / (double)fx2int(y) );
else if (LONGFLOAT_P(y))
return make_float( fx2int(x) / extract_float(y) );
}
else if (LONGFLOAT_P(x))
{
if (OBJ_ISA_FIXNUM(y))
return make_float( extract_float(x) / fx2int(y) );
else if (LONGFLOAT_P(y))
return make_float( extract_float(x) / extract_float(y) );
}
scheme_error( "(base/ ~s ~s): argument not basic", 2, x, y );
return ZERO;
}
static int float_cmp( IEEE_64 a, IEEE_64 b )
{
if (a < b)
return -1;
else if (a > b)
return 1;
else
return 0;
}
int basic_cmp( obj x, obj y )
{
if (OBJ_ISA_FIXNUM(x))
{
if (OBJ_ISA_FIXNUM(y))
{
if (EQ(x,y))
return 0;
else if (FX_LT(x,y))
return -1;
else
return 1;
}
else if (LONGFLOAT_P(y))
{
return float_cmp( (IEEE_64)fx2int(x), extract_float(y) );
}
}
else if (LONGFLOAT_P(x))
{
if (OBJ_ISA_FIXNUM(y))
return float_cmp( extract_float(x), (IEEE_64)fx2int(y) );
else if (LONGFLOAT_P(y))
return float_cmp( extract_float(x), extract_float(y) );
}
scheme_error( "(base-cmp ~s ~s): argument not basic", 2, x, y );
return NO;
}
|