method
div
v1_9_1_378 -
Show latest stable
-
0 notes -
Class: BigDecimal
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (0)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (38)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
div(p1, p2 = v2)
public
Hide source
static VALUE BigDecimal_div2(int argc, VALUE *argv, VALUE self) { ENTER(5); VALUE b,n; int na = rb_scan_args(argc,argv,"11",&b,&n); if(na==1) { /* div in Float sense */ VALUE obj; Real *div=NULL; Real *mod; obj = BigDecimal_DoDivmod(self,b,&div,&mod); if(obj!=(VALUE)0) return obj; if(VpIsNaN(div) && rb_equal(b, INT2FIX(0))) { rb_raise(rb_eZeroDivError, "divided by 0"); } return BigDecimal_to_i(ToValue(div)); } else { /* div in BigDecimal sense */ U_LONG ix = (U_LONG)GetPositiveInt(n); if(ix==0) return BigDecimal_div(self,b); else { Real *res=NULL; Real *av=NULL, *bv=NULL, *cv=NULL; U_LONG mx = (ix+VpBaseFig()*2); U_LONG pl = VpSetPrecLimit(0); GUARD_OBJ(cv,VpCreateRbObject(mx,"0")); GUARD_OBJ(av,GetVpValue(self,1)); GUARD_OBJ(bv,GetVpValue(b,1)); mx = av->Prec + bv->Prec + 2; if(mx <= cv->MaxPrec) mx = cv->MaxPrec+1; GUARD_OBJ(res,VpCreateRbObject((mx * 2 + 2)*VpBaseFig(), "#0")); VpDivd(cv,res,av,bv); VpSetPrecLimit(pl); VpLeftRound(cv,VpGetRoundMode(),ix); return ToValue(cv); } } }