Sandro Hardy |
Hello everyone,
is it there a way to increase the computing precision in Scilab beyond the regular "double precision"? In Scilab this example gives me a wrong result: -->290017/10000 ans = 29.001699999999999590727 R is more accurate (Matlab also): > 290017/10000 [1] 29.0017 In R I can even increase the precison: > options(digits=10) Is this also possible with Scilab? Similar question for big numbers, is there a "standard" solution for this (BigIntegers)? In Scilab: -->a=635037699992127443 a = 635037699992127488. -->b=635037699992127444 b = 635037699992127488. -->a-b ans = 0. I would expect a warning, but I get get a wrong result. At least the output gives me the hint, that the variable was not set accurately. The solution is called bigz in R (VPI in Matlab) and work like this: > a=as.bigz('635037699992127443'); > b=as.bigz('635037699992127444'); > a-b Big Integer ('bigz') : [1] -1 Thanks in advance for any hints. Sandro -- Sandro Hardy, M.Sc. Multimedia Communications Lab (KOM) http://www.kom.tu-darmstadt.de Technische Universitaet Darmstadt Dept. of Electrical Engineering & Information Technology tel: +49 6151 16 75164 fax: +49 6151 16 6152 E-Mail: [hidden email] postal address: TU Darmstadt, FB 18, KOM, Rundeturmstr. 10, S320/106 D-64283 Darmstadt, Germany _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
28.06.2013 14:26, Sandro Hardy пишет:
> Hello everyone, > > is it there a way to increase the computing precision in Scilab beyond > the regular "double precision"? > > In Scilab this example gives me a wrong result: > -->290017/10000 > ans = > > 29.001699999999999590727 > > R is more accurate (Matlab also): > > 290017/10000 > [1] 29.0017 > > In R I can even increase the precison: > > options(digits=10) > > Is this also possible with Scilab? > > Similar question for big numbers, is there a "standard" solution for > this (BigIntegers)? > > In Scilab: > -->a=635037699992127443 > a = > > 635037699992127488. > > -->b=635037699992127444 > b = > > 635037699992127488. > > -->a-b > ans = > > 0. > > I would expect a warning, but I get get a wrong result. At least the > output gives me the hint, that the variable was not set accurately. > > The solution is called bigz in R (VPI in Matlab) and work like this: > > > a=as.bigz('635037699992127443'); > > b=as.bigz('635037699992127444'); > > a-b > Big Integer ('bigz') : > [1] -1 > > Thanks in advance for any hints. > > Sandro > > I suppose it is common problem of representation of floating point numbers. Actually, I don't think that Matlab is more accurate. There is an interest document http://www.scilab.org/content/download/395/2850/file/ScilabTec_Keynote.pdf . Stanislav _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Mathieu Dubois |
In reply to this post by Sandro Hardy
On 2013-06-28 10:26, Sandro Hardy wrote:
> Hello everyone, > > is it there a way to increase the computing precision in Scilab > beyond the regular "double precision"? > > In Scilab this example gives me a wrong result: > -->290017/10000 > ans = > > 29.001699999999999590727 > > R is more accurate (Matlab also): >> 290017/10000 > [1] 29.0017 > > In R I can even increase the precison: >> options(digits=10) > > Is this also possible with Scilab? > -->290017/10000 ans = 29.0017 The R "digits" option only change the number of digits that are displayed not the precision of the computation. So under R: > options(digits=22) > 290017/10000 [1] 29.00169999999999959073 The scilab equivalent of option(digit = ...) is format (I guess that youhave changed that in your example). -->format(24) -->290017/10000 ans = 29.00169999999999959073 Similarly in Matlab: >> format LONG >> 290017/10000 ans = 29.001700000000000 I think that R and Matlab use the native double type (as scilab) so precision is the same. The fact that your operation is wrong is a fundamental limit of floating point representation. There is a scilab toolbox for multiprecision computing (http://forge.scilab.org/index.php/p/mpscilab/) but I don't know the state of it. It probably solves the big integers problem. > Similar question for big numbers, is there a "standard" solution for > this (BigIntegers)? > > In Scilab: > -->a=635037699992127443 > a = > > 635037699992127488. > > -->b=635037699992127444 > b = > > 635037699992127488. > > -->a-b > ans = > > 0. > > I would expect a warning, but I get get a wrong result. At least the > output gives me the hint, that the variable was not set accurately. > > The solution is called bigz in R (VPI in Matlab) and work like this: > >> a=as.bigz('635037699992127443'); >> b=as.bigz('635037699992127444'); >> a-b > Big Integer ('bigz') : > [1] -1 > > Thanks in advance for any hints. > > Sandro > > > -- > Sandro Hardy, M.Sc. > > Multimedia Communications Lab (KOM) > http://www.kom.tu-darmstadt.de > Technische Universitaet Darmstadt > Dept. of Electrical Engineering & Information Technology > tel: +49 6151 16 75164 fax: +49 6151 16 6152 > E-Mail: [hidden email] > postal address: TU Darmstadt, FB 18, KOM, Rundeturmstr. 10, S320/106 > D-64283 Darmstadt, Germany > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Sandro Hardy |
In reply to this post by Stanislav
Hi,
> Hi. > I suppose it is common problem of representation of floating point numbers. > Actually, I don't think that Matlab is more accurate. There is an > interest document It was not my intension to claim that Matlab is more precise in general. Just for the few operations I tested I need a better solution than the regular Scilab double precision. > http://www.scilab.org/content/download/395/2850/file/ScilabTec_Keynote.pdf This is a great document. Especially for motivting student to care about there computations... Best wishes Sandro -- Sandro Hardy, M.Sc. Multimedia Communications Lab (KOM) http://www.kom.tu-darmstadt.de Technische Universitaet Darmstadt Dept. of Electrical Engineering & Information Technology tel: +49 6151 16 75164 fax: +49 6151 16 6152 E-Mail: [hidden email] postal address: TU Darmstadt, FB 18, KOM, Rundeturmstr. 10, S320/106 D-64283 Darmstadt, Germany _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Sandro Hardy |
In reply to this post by Mathieu Dubois
Hi Mathieu,
thank you for your answer. I forgot to care about the truncation of the zeros although the output format is set to more digits. I fooled myself this way... so I assumed R and matlab would use different internal represantions to achieve higher precisions, but obviously they don't... Allowing increased precsion was started with http://forge.scilab.org/index.php/p/dbldbl/ but it seems they stopped the development. > There is a scilab toolbox for multiprecision computing > (http://forge.scilab.org/index.php/p/mpscilab/) but I don't know the > state of it. It probably solves the big integers problem. Thank you. I will try this. Best wishes Sandro -- Sandro Hardy, M.Sc. Multimedia Communications Lab (KOM) http://www.kom.tu-darmstadt.de Technische Universitaet Darmstadt Dept. of Electrical Engineering & Information Technology tel: +49 6151 16 75164 fax: +49 6151 16 6152 E-Mail: [hidden email] postal address: TU Darmstadt, FB 18, KOM, Rundeturmstr. 10, S320/106 D-64283 Darmstadt, Germany _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users |
Free forum by Nabble | Edit this page |