ruby-changes:52506
From: hsbt <ko1@a...>
Date: Thu, 13 Sep 2018 15:59:51 +0900 (JST)
Subject: [ruby-changes:52506] hsbt:r64717: Move SHIGEO branch to tags.
hsbt 2018-09-13 15:59:47 +0900 (Thu, 13 Sep 2018) New Revision: 64717 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64717 Log: Move SHIGEO branch to tags. Added directories: tags/SHIGEO/ Removed directories: branches/SHIGEO/ Index: SHIGEO/ext/bigfloat/depend =================================================================== --- SHIGEO/ext/bigfloat/depend (revision 64716) +++ SHIGEO/ext/bigfloat/depend (nonexistent) @@ -1 +0,0 @@ -bigfloat.o: bigfloat.c bigfloat.h $(hdrdir)/ruby.h Property changes on: SHIGEO/ext/bigfloat/depend ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -Author Date Id Revision \ No newline at end of property Index: SHIGEO/ext/bigfloat/bigfloat.c =================================================================== --- SHIGEO/ext/bigfloat/bigfloat.c (revision 64716) +++ SHIGEO/ext/bigfloat/bigfloat.c (nonexistent) @@ -1,4674 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/SHIGEO/ext/bigfloat/bigfloat.c#L0 -/* - * - * Ruby BIGFLOAT(Variable Precision) extension library. - * - * Copyright(C) 1999 by Shigeo Kobayashi(shigeo@t...) - * - * You may distribute under the terms of either the GNU General Public - * License or the Artistic License, as specified in the README file - * of this BigFloat distribution. - * - * Version 1.1.8(2001/10/23) - * bug(reported by Stephen Legrand) on VpAlloc() fixed. - * Version 1.1.7(2001/08/27) - * limit() method added for global upper limit of precision. - * VpNewRbClass() added for new() to create new object from klass. - * Version 1.1.6(2001/03/27) - * Changed to use USE_XMALLOC & USE_XFREE - * ENTER,SAVE & GUARD_OBJ macro used insted of calling rb_gc_mark(). - * modulo added to keep consistency with Float. - * Bug in abs(0.0) fixed. - * == and != changed not to coerce. - * - * Version 1.1.5(2001/02/16) - * (Bug fix) BASE_FIG & DBLE_FIG changed to S_LONG - * Effective figures for sqrt() extended. - * - * Version 1.1.4(2000/10/01) - * nan?,infinite?,finite?,truncate added. - * - * Version 1.1.3(2000/06/16) - * Optional parameter is now allowed for ceil,floor,and round(1.1.2). - * Meanings of the optional parameter for ceil,floor,and round changed(1.1.3). - * - */ - -#include "ruby.h" -#include <stdio.h> -#include <stdlib.h> -#ifdef NT -#include <malloc.h> -#endif /* defined NT */ -#include "ruby.h" -#include "math.h" -#include "version.h" - -VALUE rb_cBigfloat; - -#if RUBY_VERSION_CODE > 150 -# define rb_str2inum rb_cstr2inum -#endif - -#include "bigfloat.h" - -/* - * In Windows DLL,using xmalloc() may result to an application error. - * This is defaulted from 1.1.6. - */ -#define USE_XMALLOC - -/* - * #define USE_XFREE calls xfree() instead of free(). - * If USE_XFREE is defined,then xfree() in gc.c must - * be exported for other modules. - * This is defaulted from 1.1.6. - */ -#define USE_XFREE - -/* - * To builtin BIGFLOAT into ruby -#define BUILTIN_BIGFLOAT - * and modify inits.c to call Init_Bigfloat(). - * Class name for builtin BIGFLOAT is "Bigfloat". - * Class name for ext. library is "BigFloat". - */ -#ifdef BUILTIN_BIGFLOAT -/* Builtin BIGFLOAT */ -#define BIGFLOAT_CLASS_NAME "Bigfloat" -#define BIGFLOAT Init_Bigfloat -#else -/* In case of ext. library */ -#define BIGFLOAT_CLASS_NAME "BigFloat" -#define BIGFLOAT Init_BigFloat -#endif /* BUILTIN_BIGFLOAT */ -#define Initialize(x) x() - -/* - * Uncomment if you need Float's Inf NaN instead of BigFloat's. - * -#define USE_FLOAT_VALUE -*/ - -/* MACRO's to guard objects from GC by keeping it in stack */ -#define ENTER(n) volatile VALUE vStack[n];int iStack=0 -#define PUSH(x) vStack[iStack++] = (unsigned long)(x); -#define SAVE(p) PUSH(p->obj); -#define GUARD_OBJ(p,y) {p=y;SAVE(p);} - -/* - * =================================================================== - * - * Ruby Interface part - * - * =================================================================== - */ -static ID coerce; - -static VALUE BigFloat_new(); /* new */ -static VALUE BigFloat_limit(); /* limit */ -static VALUE BigFloat_to_s(); /* to_s */ -static VALUE BigFloat_to_i(); /* to_i */ -static VALUE BigFloat_to_s2(); /* to_s2(spacing) */ -static VALUE BigFloat_to_parts();/* to_parts(4 parts) */ -static VALUE BigFloat_uplus(); /* a = +a (unary plus) */ -static VALUE BigFloat_asign(); /* assign! */ -static VALUE BigFloat_asign2(); /* assign */ -static VALUE BigFloat_add(); /* + */ -static VALUE BigFloat_sub(); /* - */ -static VALUE BigFloat_add2(); /* add */ -static VALUE BigFloat_sub2(); /* sub */ -static VALUE BigFloat_add3(); /* add!(c,a,b) */ -static VALUE BigFloat_sub3(); /* sub!(c,a,b) */ -static VALUE BigFloat_neg(); /* -(unary) */ -static VALUE BigFloat_mult(); /* * */ -static VALUE BigFloat_mult2(); /* mult */ -static VALUE BigFloat_mult3(); /* mult! */ -static VALUE BigFloat_div(); /* / */ -static VALUE BigFloat_mod(); /* % */ -static VALUE BigFloat_remainder(); /* remainder */ -static VALUE BigFloat_divmod(); /* divmod */ -static VALUE BigFloat_divmod2();/* div */ -static VALUE BigFloat_divmod4();/* divmod! */ -static VALUE BigFloat_dup(); /* dup */ -static VALUE BigFloat_abs(); /* abs */ -static VALUE BigFloat_sqrt(); /* sqrt */ -static VALUE BigFloat_fix(); /* fix */ -static VALUE BigFloat_round(); /* round */ -static VALUE BigFloat_frac(); /* frac */ -static VALUE BigFloat_e(); /* e(=2.18281828459.....) */ -static VALUE BigFloat_pai(); /* pai(=3.141592653589.....) */ -static VALUE BigFloat_power(); /* self**p */ -static VALUE BigFloat_exp(); /* e**x */ -static VALUE BigFloat_sincos(); /* sin & cos */ -static VALUE BigFloat_comp(); /* self <=> r */ -static VALUE BigFloat_eq(); /* self == r */ -static VALUE BigFloat_ne(); /* self != r */ -static VALUE BigFloat_lt(); /* self < r */ -static VALUE BigFloat_le(); /* self <= r */ -static VALUE BigFloat_gt(); /* self > r */ -static VALUE BigFloat_ge(); /* self >= r */ -static VALUE BigFloat_zero(); /* self==0 ? */ -static VALUE BigFloat_nonzero();/* self!=0 ? */ -static VALUE BigFloat_floor(); /* floor(self) */ -static VALUE BigFloat_ceil(); /* ceil(self) */ -static VALUE BigFloat_coerce(); /* coerce */ -static VALUE BigFloat_inspect();/* inspect*/ -static VALUE BigFloat_exponent();/* exponent */ -static VALUE BigFloat_sign();/* sign */ -static VALUE BigFloat_mode(); /* mode */ -static VALUE BigFloat_induced_from(); /* induced_from */ -static void BigFloat_delete(); /* free */ - -/* Added for ruby 1.6.0 */ -static VALUE BigFloat_IsNaN(); -static VALUE BigFloat_IsInfinite(); -static VALUE BigFloat_IsFinite(); -static VALUE BigFloat_truncate(); - -static VALUE DoSomeOne(); -/* Following 3 functions borrowed from numeric.c */ -static VALUE coerce_body(); -static VALUE coerce_rescue(); -static void do_coerce(); - -static VALUE -DoSomeOne(x, y) - VALUE x, y; -{ - do_coerce(&x, &y); - return rb_funcall(x, rb_frame_last_func(), 1, y); -} - -static VALUE -coerce_body(x) - VALUE *x; -{ - return rb_funcall(x[1], coerce, 1, x[0]); -} - -static VALUE -coerce_rescue(x) - VALUE *x; -{ - rb_raise(rb_eTypeError, "%s can't be coerced into %s", - rb_special_const_p(x[1])? - STR2CSTR(rb_inspect(x[1])): - rb_class2name(CLASS_OF(x[1])), - rb_class2name(CLASS_OF(x[0]))); - return (VALUE)0; -} - -static void -do_coerce(x, y) - VALUE *x, *y; -{ - VALUE ary; - VALUE a[2]; - - a[0] = *x; a[1] = *y; - ary = rb_rescue(coerce_body, (VALUE)a, coerce_rescue, (VALUE)a); - if (TYPE(ary) != T_ARRAY || RARRAY(ary)->len != 2) { - rb_raise(rb_eTypeError, "coerce must return [x, y]"); - } - - *x = RARRAY(ary)->ptr[0]; - *y = RARRAY(ary)->ptr[1]; -} - -void -Initialize(BIGFLOAT) -{ - - /* Initialize VP routines */ - VpInit((U_LONG)0); - - coerce = rb_intern("coerce"); - - /* Class and method registration */ - rb_cBigfloat = rb_define_class(BIGFLOAT_CLASS_NAME,rb_cNumeric); - - /* Class methods */ - rb_define_singleton_method(rb_cBigfloat, "mode", BigFloat_mode, 2); - rb_define_singleton_method(rb_cBigfloat, "new", BigFloat_new, -1); - rb_define_singleton_method(rb_cBigfloat, "limit", BigFloat_limit, -1); - rb_define_singleton_method(rb_cBigfloat, "E", BigFloat_e, 1); - rb_define_singleton_method(rb_cBigfloat, "PI", BigFloat_pai, 1); - rb_define_singleton_method(rb_cBigfloat, "assign!", BigFloat_asign, 3); - rb_define_singleton_method(rb_cBigfloat, "add!", BigFloat_add3, 3); - rb_define_singleton_method(rb_cBigfloat, "sub!", BigFloat_sub3, 3); - rb_define_singleton_method(rb_cBigfloat, "mult!", BigFloat_mult3, 3); - rb_define_singleton_method(rb_cBigfloat, "div!",BigFloat_divmod4, 4); - - rb_define_method(rb_cBigfloat, "assign", BigFloat_asign2, 2); - rb_define_method(rb_cBigfloat, "add", BigFloat_add2, 2); - rb_define_method(rb_cBigfloat, "sub", BigFloat_sub2, 2); - rb_define_method(rb_cBigfloat, "mult", BigFloat_mult2, 2); - rb_define_method(rb_cBigfloat, "div",BigFloat_divmod2, 2); - - rb_define_singleton_method(rb_cBigfloat, "induced_from",BigFloat_induced_from, 1); - - rb_define_const(rb_cBigfloat, "BASE", INT2FIX((S_INT)VpBaseVal())); - - /* Exception constants */ - rb_define_const(rb_cBigfloat, "EXCEPTION_ALL",INT2FIX(VP_EXCEPTION_ALL)); - rb_define_const(rb_cBigfloat, "EXCEPTION_NaN",INT2FIX(VP_EXCEPTION_NaN)); - rb_define_const(rb_cBigfloat, "EXCEPTION_INFINITY",INT2FIX(VP_EXCEPTION_INFINITY)); - rb_define_const(rb_cBigfloat, "EXCEPTION_UNDERFLOW",INT2FIX(VP_EXCEPTION_UNDERFLOW)); - rb_define_const(rb_cBigfloat, "EXCEPTION_OVERFLOW",INT2FIX(VP_EXCEPTION_OVERFLOW)); - rb_define_const(rb_cBigfloat, "EXCEPTION_ZERODIVIDE",INT2FIX(VP_EXCEPTION_ZERODIVIDE)); - - /* Constants for sign value */ - rb_define_const(rb_cBigfloat, "SIGN_NaN",INT2FIX(VP_SIGN_NaN)); - rb_define_const(rb_cBigfloat, "SIGN_POSITIVE_ZERO",INT2FIX(VP_SIGN_POSITIVE_ZERO)); - rb_define_const(rb_cBigfloat, "SIGN_NEGATIVE_ZERO",INT2FIX(VP_SIGN_NEGATIVE_ZERO)); - rb_define_const(rb_cBigfloat, "SIGN_POSITIVE_FINITE",INT2FIX(VP_SIGN_POSITIVE_FINITE)); - rb_define_const(rb_cBigfloat, "SIGN_NEGATIVE_FINITE",INT2FIX(VP_SIGN_NEGATIVE_FINITE)); - rb_define_const(rb_cBigfloat, "SIGN_POSITIVE_INFINITE",INT2FIX(VP_SIGN_POSITIVE_INFINITE)); - rb_define_const(rb_cBigfloat, "SIGN_NEGATIVE_INFINITE",INT2FIX(VP_SIGN_NEGATIVE_INFINITE)); - - /* instance methods */ - rb_define_method(rb_cBigfloat, "to_s", BigFloat_to_s, 0); - rb_define_method(rb_cBigfloat, "to_i", BigFloat_to_i, 0); - rb_define_method(rb_cBigfloat, "to_s2", BigFloat_to_s2, 1); - rb_define_method(rb_cBigfloat, "to_parts", BigFloat_to_parts, 0); - rb_define_method(rb_cBigfloat, "+", BigFloat_add, 1); - rb_define_method(rb_cBigfloat, "-", BigFloat_sub, 1); - rb_define_method(rb_cBigfloat, "+@", BigFloat_uplus, 0); - rb_define_method(rb_cBigfloat, "-@", BigFloat_neg, 0); - rb_define_method(rb_cBigfloat, "*", BigFloat_mult, 1); - rb_define_method(rb_cBigfloat, "/", BigFloat_div, 1); - rb_define_method(rb_cBigfloat, "%", BigFloat_mod, 1); - rb_define_method(rb_cBigfloat, "modulo", BigFloat_mod, 1); - - rb_define_method(rb_cBigfloat, "remainder", BigFloat_remainder, 1); - rb_define_method(rb_cBigfloat, "divmod", BigFloat_divmod, 1); - rb_define_method(rb_cBigfloat, "dup", BigFloat_dup, 0); - rb_define_method(rb_cBigfloat, "to_f", BigFloat_dup, 0); /* to_f === dup */ - rb_define_method(rb_cBigfloat, "abs", BigFloat_abs, 0); - rb_define_method(rb_cBigfloat, "sqrt", BigFloat_sqrt, 1); - rb_define_method(rb_cBigfloat, "fix", BigFloat_fix, 0); - rb_define_method(rb_cBigfloat, "round", BigFloat_round, -1); - rb_define_method(rb_cBigfloat, "frac", BigFloat_frac, 0); - rb_define_method(rb_cBigfloat, "floor", BigFloat_floor, -1); - rb_define_method(rb_cBigfloat, "ceil", BigFloat_ceil, -1); - rb_define_method(rb_cBigfloat, "power", BigFloat_power, 1); - rb_define_method(rb_cBigfloat, "exp", BigFloat_exp, 1); - rb_define_method(rb_cBigfloat, "sincos", BigFloat_sincos, 1); - rb_define_method(rb_cBigfloat, "<=>", BigFloat_comp, 1); - rb_define_method(rb_cBigfloat, "==", BigFloat_eq, 1); - rb_define_method(rb_cBigfloat, "===", BigFloat_eq, 1); - rb_define_method(rb_cBigfloat, "!=", BigFloat_ne, 1); - rb_define_method(rb_cBigfloat, "<", BigFloat_lt, 1); - rb_define_method(rb_cBigfloat, "<=", BigFloat_le, 1); - rb_define_method(rb_cBigfloat, ">", BigFloat_gt, 1); - rb_define_method(rb_cBigfloat, ">=", BigFloat_ge, 1); - rb_define_method(rb_cBigfloat, "zero?", BigFloat_zero, 0); - rb_define_method(rb_cBigfloat, "nonzero?", BigFloat_nonzero, 0); - rb_define_method(rb_cBigfloat, "coerce", BigFloat_coerce, 1); - rb_define_method(rb_cBigfloat, "inspect", BigFloat_inspect, 0); - rb_define_method(rb_cBigfloat, "exponent", BigFloat_exponent, 0); - rb_define_method(rb_cBigfloat, "sign", BigFloat_sign, 0); - /* newly added for ruby 1.6.0 */ - rb_define_method(rb_cBigfloat, "nan?", BigFloat_IsNaN, 0); - rb_define_method(rb_cBigfloat, "infinite?", BigFloat_IsInfinite, 0); - rb_define_method(rb_cBigfloat, "finite?", BigFloat_IsFinite, 0); - rb_define_method(rb_cBigfloat, "truncate", BigFloat_truncate, -1); -} - -static void -CheckAsign(x,y) - VALUE x; - VALUE y; -{ - if(x==y) - rb_fatal("Bad assignment(the same object appears on both LHS and RHS)."); -} - -static VALUE -BigFloat_mode(self,which,val) - VALUE self; - VALUE which; - VALUE val; -{ - unsigned short fo = VpGetException(); - unsigned short f; - - if(TYPE(which)!=T_FIXNUM) return INT2FIX(fo); - if(val!=Qfalse && val!=Qtrue) return INT2FIX(fo); - - f = (unsigned short)NUM2INT(which); - if(f&VP_EXCEPTION_INFINITY) { - fo = VpGetException(); - VpSetException((unsigned short)((val==Qtrue)?(fo|VP_EXCEPTION_INFINITY): - (fo&(~VP_EXCEPTION_INFINITY)))); - } - if(f&VP_EXCEPTION_NaN) { - fo = VpGetException(); - VpSetException((unsigned short)((val==Qtrue)?(fo|VP_EXCEPTION_NaN): - (fo&(~VP_EXCEPTION_NaN)))); - } - fo = VpGetException(); - return INT2FIX(fo); -} - -static U_LONG -#ifdef HAVE_STDARG_PROTOTYPES -GetAddSubPrec(Real *a,Real *b) -#else -GetAddSubPrec(a,b) - Real *a; - Real *b; -#endif /* HAVE_STDARG_PROTOTYPES */ -{ - U_LONG mxs; - U_LONG mx = a->Prec; - S_INT d; - - if(!VpIsDef(a) || !VpIsDef(b)) return (-1L); - if(mx < b->Prec) mx = b->Prec; - if(a->exponent!=b->exponent) { - mxs = mx; - d = a->exponent - b->exponent; - if(d<0) d = -d; - mx = mx+(U_LONG)d; - if(mx<mxs) { - return VpException(VP_EXCEPTION_INFINITY,"Exponent overflow",0); - } - } - return mx; -} - -static S_INT -#ifdef HAVE_STDARG_PROTOTYPES -GetPositiveInt(VALUE v) -#else -GetPositiveInt(v) - VALUE v; -#endif /* HAVE_STDARG_PROTOTYPES */ -{ - S_INT n; - Check_Type(v, T_FIXNUM); - n = NUM2INT(v); - if(n <= 0) { - rb_fatal("Zero or negative argument not permitted."); - } - return n; -} - -static VALUE -#ifdef HAVE_STDARG_PROTOTYPES -ToValue(Real *p) -#else -ToValue(p) - Real *p; -#endif /* HAVE_STDARG_PROTOTYPES */ -{ - -#ifdef USE_FLOAT_VALUE - VALUE v; - if(VpIsNaN(p)) { - VpException(VP_EXCEPTION_NaN,"Computation results to 'NaN'(Not a Number)",0); - v = rb_float_new(VpGetDoubleNaN()); - } else if(VpIsPosInf(p)) { - VpException(VP_EXCEPTION_INFINITY,"Computation results to 'Infinity'",0); - v = rb_float_new(VpGetDoublePosInf()); - } else if(VpIsNegInf(p)) { - VpException(VP_EXCEPTION_INFINITY,"Computation results to '-Infinity'",0); - v = rb_float_new(VpGetDoubleNegInf()); - } else { - v = (VALUE)p->obj; - } - return v; - -#else /* ~USE_FLOAT_VALUE */ - if(VpIsNaN(p)) { - VpException(VP_EXCEPTION_NaN,"Computation results to 'NaN'(Not a Number)",0); - } else if(VpIsPosInf(p)) { - VpException(VP_EXCEPTION_INFINITY,"Computation results to 'Infinity'",0); - } else if(VpIsNegInf(p)) { - VpException(VP_EXCEPTION_INFINITY,"Computation results to '-Infinity'",0); - } - return p->obj; -#endif /* ~USE_FLOAT_VALUE */ -} - -VP_EXPORT Real * -#ifdef HAVE_STDARG_PROTOTYPES -VpNewRbClass(U_LONG mx,char *str,VALUE klass) -#else -VpNewRbClass(mx,str,klass) - U_LONG mx; - char *str; - VALUE klass; -#endif /* HAVE_STDARG_PROTOTYPES */ -{ - Real *pv = VpAlloc(mx,str); - pv->obj = (VALUE)Data_Wrap_Struct(klass, 0, BigFloat_delete, pv); - return pv; -} - -VP_EXPORT Real * -#ifdef HAVE_STDARG_PROTOTYPES -VpCreateRbObject(U_LONG mx,char *str) -#else -VpCreateRbObject(mx,str) - U_LONG mx; - char *str; -#endif /* HAVE_STDARG_PROTOTYPES */ -{ - Real *pv = VpAlloc(mx,str); - pv->obj = (VALUE)Data_Wrap_Struct(rb_cBigfloat, 0, BigFloat_delete, pv); - return pv; -} - -static Real * -#ifdef HAVE_STDARG_PROTOTYPES -GetVpValue(VALUE v,int must) -#else -GetVpValue(v,must) - VALUE v; - int must; -#endif /* HAVE_STDARG_PROTOTYPES */ -{ - double dv; - Real *pv; - VALUE bg; - char szD[128]; - - switch(TYPE(v)) - { - case T_DATA: - if(RDATA(v)->dfree ==(void *) BigFloat_delete) { - Data_Get_Struct(v, Real, pv); - return pv; - } else { - goto SomeOneMayDoIt; - } - break; - case T_FIXNUM: - sprintf(szD, "%d", NUM2INT(v)); - return VpCreateRbObject(VpBaseFig() * 2 + 1, szD); - case T_FLOAT: - pv = VpCreateRbObject(VpDblFig()*2,"0"); - dv = RFLOAT(v)->value; - /* From float */ - if (isinf(dv)) { - VpException(VP_EXCEPTION_INFINITY,"Computation including infinity",0); - if(dv==VpGetDoublePosInf()) { - VpSetPosInf(pv); - } else { - VpSetNegInf(pv); - } - } else - if (isnan(dv)) { - VpException(VP_EXCEPTION_NaN,"Computation including NaN(Not a number)",0); - VpSetNaN(pv); - } else { - if (VpIsNegDoubleZero(dv)) { - VpSetNegZero(pv); - } else if(dv==0.0) { - VpSetPosZero(pv); - } else if(dv==1.0) { - VpSetOne(pv); - } else if(dv==-1.0) { - VpSetOne(pv); - pv->sign = -pv->sign; - } else { - VpDtoV(pv,dv); - } - } - return pv; - case T_STRING: - Check_SafeStr(v); - return VpCreateRbObject(strlen(RSTRING(v)->ptr) + VpBaseFig() + 1, - RSTRING(v)->ptr); - case T_BIGNUM: - bg = rb_big2str(v, 10); - return VpCreateRbObject(strlen(RSTRING(bg)->ptr) + VpBaseFig() + 1, - RSTRING(bg)->ptr); - default: - goto SomeOneMayDoIt; - } - -SomeOneMayDoIt: - if(must) { - rb_raise(rb_eTypeError, "%s can't be coerced into BigFloat", - rb_special_const_p(v)? - STR2CSTR(rb_inspect(v)): - rb_class2name(CLASS_OF(v))); - } - return NULL; /* NULL means to coerce */ -} - -static VALUE -BigFloat_IsNaN(self) - VALUE self; -{ - Real *p = GetVpValue(self,1); - if(VpIsNaN(p)) return Qtrue; - return Qfalse; -} - -static VALUE -BigFloat_IsInfinite(self) - VALUE self; -{ - Real *p = GetVpValue(self,1); - if(VpIsInf(p)) return Qtrue; - return Qfalse; -} - -static VALUE -BigFloat_IsFinite(self) - VALUE self; -{ - Real *p = GetVpValue(self,1); - if(VpIsNaN(p)) return Qfalse; - if(VpIsInf(p)) return Qfalse; - return Qtrue; -} - -static VALUE -BigFloat_to_i(self) - VALUE self; -{ - ENTER(5); - int e,n,i,nf; - U_LONG v,b,j; - char *psz,*pch; - Real *p; - - GUARD_OBJ(p,GetVpValue(self,1)); - - if(!VpIsDef(p)) return Qnil; /* Infinity or NaN not converted. */ - - e = VpExponent10(p); - if(e<=0) return INT2FIX(0); - nf = VpBaseFig(); - if(e<=nf) { - e = VpGetSign(p)*p->frac[0]; - return INT2FIX(e); - } - psz = ALLOCA_N(char,(unsigned int)(e+nf+2)); - - n = (e+nf-1)/nf; - pch = psz; - if(VpGetSign(p)<0) *pch++ = '-'; - for(i=0;i<n;++i) { - v = p->frac[i]; - b = VpBaseVal()/10; - while(b) { - j = v/b; - *pch++ = (char)(j + '0'); - v -= j*b; - b /= 10; - } - } - *pch++ = 0; - return rb_str2inum(psz,10); -} - -static VALUE -BigFloat_induced_from(self,x) - VALUE self; - VALUE x; -{ - Real *p = GetVpValue(x,1); - return p->obj; -} - -static VALUE -BigFloat_coerce(self, other) - VALUE self; - VALUE other; -{ - ENTER(2); - VALUE obj; - Real *b; - GUARD_OBJ(b,GetVpValue(other,1)); - obj = rb_ary_new(); - obj = rb_ary_push(obj, b->obj); - obj = rb_ary_push(obj, self); - return obj; -} - -static VALUE -BigFloat_uplus(self) - VALUE self; -{ - return self; -} - -static VALUE -BigFloat_add(self, r) - VALUE self; - VALUE r; -{ - ENTER(5); - Real *c, *a, *b; - U_LONG mx; - - GUARD_OBJ(a,GetVpValue(self,1)); - b = GetVpValue(r,0); - if(!b) return DoSomeOne(self,r); - SAVE(b); - - if(VpIsNaN(b)) return b->obj; - if(VpIsNaN(a)) return a->obj; - mx = GetAddSubPrec(a,b); - if(mx==(-1L)) { - GUARD_OBJ(c,VpCreateRbObject(VpBaseFig() + 1, "0")); - Vp (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/