2
Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
4
This file is part of GNU Common Lisp, herein referred to as GCL
6
GCL is free software; you can redistribute it and/or modify it under
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
8
the Free Software Foundation; either version 2, or (at your option)
11
GCL is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14
License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with GCL; see the file COPYING. If not, write to the Free Software
18
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
IMPLEMENTATION-DEPENDENT
26
This file creates some implementation dependent constants.
32
#include "num_include.h"
38
if (type_of(x) != t_fixnum)
39
FEwrong_type_argument(sLfixnum, x);
46
if (type_of(x) != t_fixnum || fix(x) < 0)
47
FEerror("~S is not a non-negative fixnum.", 1, x);
51
object small_fixnum ( int i ) {
53
assert ( ( -SMALL_FIXNUM_LIMIT <= i ) && ( i < SMALL_FIXNUM_LIMIT ) );
54
(object) small_fixnum_table + SMALL_FIXNUM_LIMIT + i;
58
#if !defined(IM_FIX_BASE)
60
#define BIGGER_FIXNUM_RANGE
62
#ifdef BIGGER_FIXNUM_RANGE
63
struct {int min,max;} bigger_fixnums;
65
struct fixnum_struct *bigger_fixnum_table;
66
DEFUN_NEW("ALLOCATE-BIGGER-FIXNUM-RANGE",object,fSallocate_bigger_fixnum_range,SI,2,2,NONE,OI,IO,OO,OO,(fixnum min,fixnum max),"") {
68
if (min > max) FEerror("Need Min <= Max",0);
69
bigger_fixnum_table=(void *)malloc(sizeof(struct fixnum_struct)*(max - min));
71
for (j=min ; j < max ; j=j+1) {
72
object x=(object)(bigger_fixnum_table+j-min);
74
set_type_of(x,t_fixnum);
77
bigger_fixnums.min=min;
78
bigger_fixnums.max=max;
92
/* if (-SMALL_FIXNUM_LIMIT <= i && i < SMALL_FIXNUM_LIMIT) */
93
/* return(small_fixnum(i)); */
94
#ifdef BIGGER_FIXNUM_RANGE
95
if (bigger_fixnum_table)
96
{ if (i >= bigger_fixnums.min
97
&& i < bigger_fixnums.max)
98
return (object)(bigger_fixnum_table +(i -bigger_fixnums.min));
102
x = alloc_object(t_fixnum);
108
make_ratio(object num, object den)
110
object g, r, integer_divide1(object x, object y), get_gcd(object x, object y);
113
if (number_zerop(den))
114
FEerror("Zero denominator.", 0);
115
if (number_zerop(num))
116
return(small_fixnum(0));
117
if (type_of(den) == t_fixnum && fix(den) == 1)
119
if (number_minusp(den)) {
120
num = number_negate(num);
122
den = number_negate(den);
125
g = get_gcd(num, den);
127
num = integer_divide1(num, g);
129
den = integer_divide1(den, g);
131
if(type_of(den) == t_fixnum && fix(den) == 1) {
135
if(type_of(den) == t_fixnum && fix(den) == -1) {
136
num = number_negate(num);
140
r = alloc_object(t_ratio);
141
r->rat.rat_num = num;
142
r->rat.rat_den = den;
148
make_shortfloat(double f)
152
if (f == (shortfloat)0.0)
153
return(shortfloat_zero);
154
x = alloc_object(t_shortfloat);
155
sf(x) = (shortfloat)f;
160
make_longfloat(longfloat f)
164
if (f == (longfloat)0.0)
165
return(longfloat_zero);
166
x = alloc_object(t_longfloat);
172
make_complex(object r, object i)
177
switch (type_of(r)) {
181
switch (type_of(i)) {
187
r = make_shortfloat((shortfloat)number_to_double(r));
191
r = make_longfloat(number_to_double(r));
199
switch (type_of(i)) {
203
i = make_shortfloat((shortfloat)number_to_double(i));
207
r = make_longfloat((double)(sf(r)));
215
switch (type_of(i)) {
220
i = make_longfloat(number_to_double(i));
230
c = alloc_object(t_complex);
238
number_to_double(object x)
242
return((double)(fix(x)));
245
return(big_to_double(/* (struct bignum *) */x));
249
/* vs_base=vs_top; */
252
/* if (vs_base[0]!=small_fixnum(0)) */
253
/* return number_to_double(vs_base[0])+number_to_double(vs_base[1]); */
259
for (xx=x->rat.rat_num,yy=x->rat.rat_den,dx=number_to_double(xx),dy=number_to_double(yy);
260
dx && dy && (!ISNORMAL(dx) || !ISNORMAL(dy));) {
265
xx=integer_divide1(xx,small_fixnum(2));
266
dx=number_to_double(xx);
272
yy=integer_divide1(yy,small_fixnum(2));
273
dy=number_to_double(yy);
282
return((double)(sf(x)));
288
wrong_type_argument(TSor_rational_float, x);
294
gcl_init_number(void)
297
#if !defined(IM_FIX_BASE)
298
FFN(fSallocate_bigger_fixnum_range)(-1024,1023);
301
shortfloat_zero = alloc_object(t_shortfloat);
302
sf(shortfloat_zero) = (shortfloat)0.0;
303
longfloat_zero = alloc_object(t_longfloat);
304
lf(longfloat_zero) = (longfloat)0.0;
305
enter_mark_origin(&shortfloat_zero);
306
enter_mark_origin(&longfloat_zero);
308
make_constant("MOST-POSITIVE-FIXNUM",
309
make_fixnum(MOST_POSITIVE_FIX));
310
make_constant("MOST-NEGATIVE-FIXNUM",
311
make_fixnum(MOST_NEGATIVE_FIX));
316
gcl_init_num_arith();