BigDecimal#sqrt

  • Thread starter James Edward Gray II
  • Start date
J

James Edward Gray II

I'm trying to understand the argument to BigDecimal#sqrt. I figured
it was for precision and it does seem to affect it, but I can't
understand the exactly relationship. Can anyone tell me what the
argument controls and how?

Thanks.

James Edward Gray II
 
J

James Edward Gray II

I'm trying to understand the argument to BigDecimal#sqrt. I
figured it was for precision and it does seem to affect it, but I
can't understand the exactly relationship. Can anyone tell me what
the argument controls and how?

Let me try asking me question a different way... Is this the correct
way to get a printable sqrt() with 16 digits precision?
=> "257.9592991151890260"

James Edward Gray II
 
J

James Edward Gray II

I'm trying to understand the argument to BigDecimal#sqrt. I
figured it was for precision and it does seem to affect it, but I
can't understand the exactly relationship. Can anyone tell me what
the argument controls and how?

Let me try asking my question a different way... Is this the correct
way to get a printable square root with N digits precision (N = 16 in
this example)?
=> "257.9592991151890260"

James Edward Gray II
 
L

Lou Vanek

yeah, it looks right.
interesting format variation:

minfieldwidth = 22
precision = 16
sprintf "%*.*f", minfieldwidth, precision, BigDecimal.new("66543").sqrt(precision)
=> " 257.9592991151898786"
 
G

Gregory Brown

I'm trying to understand the argument to BigDecimal#sqrt. I figured
it was for precision and it does seem to affect it, but I can't
understand the exactly relationship. Can anyone tell me what the
argument controls and how?

This is the C source, if you haven't looked at it yet.

BigDecimal_sqrt(VALUE self, VALUE nFig)
{
ENTER(5);
Real *c, *a;
S_INT mx, n;

GUARD_OBJ(a,GetVpValue(self,1));
mx =3D a->Prec *(VpBaseFig() + 1);

n =3D GetPositiveInt(nFig) + VpDblFig() + 1;
if(mx <=3D n) mx =3D n;
GUARD_OBJ(c,VpCreateRbObject(mx, "0"));
VpSqrt(c, a);
return ToValue(c);
}

I don't fully understand what's going on with it, because my C is
pretty weak, but hopefully this will provide some insight from
someone.
 
J

James Edward Gray II

Yes.

I've written some documentation for BigDecimal which will hopefully
be checked in to Ruby some time.

Is it available online anywhere before then or could I trouble you to
send it to me privately?

James Edward Gray II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top