1

I'm working with Scilab 5.5.2 and when using the format command I can display at most 25 digits of a number. Is there a way to somehow display more than this number?

Paul Warnick
  • 903
  • 2
  • 13
  • 26

2 Answers2

1

Scilab operates with double precision floating point numbers; it does not support variable-precision arithmetics. Double precision means relative error of %eps, which is 2-52, approximately 2e-16.

This means you can't even get 25 correct decimal digits: when using format(25) you get garbage at the end. For example,

format(25); sqrt(3)

returns 1.732050807568877 1931766

I separated the last 7 digits here because they are wrong; the correct value of sqrt(3) begins with

      1.732050807568877 2935274

Of course, if you don't mind the digits being wrong, you can have as many as you want:

 strcat([sprintf('%.15f', sqrt(3)), "1111111111111111111111111111111"])

returns 1.7320508075688771111111111111111111111111111111.

But if you want to have arbitrary exceeding of real numbers, Scilab is not the right tool for the job (correction: phuclv pointed out Multiple Precision Arithmetic Toolbox which might work for you). Out of free software packages, mpmath Python library implements arbitrary precision of real numbers: it can be used directly or via Sagemath or SymPy. Commercial packages (Matlab, Maple, Mathematica) support variable precision too.

As for Scilab, I recommend using formatted print commands such as fprintf or sprintf, because they actually care about the output being meaningful. Example: printf('%.25f', sqrt(3)) returns

1.7320508075688772000000000 

with garbage replaced by zeros. The last nonzero digit is still off by 1, but at least it's not meaningless.

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • I'm new to Scilab but I probably should have considered searching for a printf function. Thank you, it's exactly what I needed. – Paul Warnick Jun 24 '16 at 19:37
0

Scilab uses double-precision floating-point type which has 53 bits of mantissa and can only be precise to ~15-17 digits. There's no reason printing digits beyond that.

If 25 digits of accuracy is needed then you can use a quadruple precision or double-double arithmetic library like ATOMS: Multiple Precision Arithmetic Toolbox details

If you need even more precision then the only way is using an arbitrary precision library like mpscilab, Xnum, etc...

Community
  • 1
  • 1
phuclv
  • 37,963
  • 15
  • 156
  • 475
  • The keyword of my question is "display" not "calculate". I'm not looking to increase the precision of Scilab's calculations, just to display a larger number of digits, no matter how correct they are. Thank you for your answer though. – Paul Warnick Jun 24 '16 at 19:39