Another take on decimal data types
rumbu
rumbu at rumbu.ro
Sat Jan 13 22:05:02 UTC 2018
On Saturday, 13 January 2018 at 20:40:20 UTC, kdevel wrote:
> On Saturday, 13 January 2018 at 19:28:40 UTC, rumbu wrote:
>> On Saturday, 13 January 2018 at 18:37:10 UTC, kdevel wrote:
>>
>>> I get large numerical dicrepancies and an exception:
>>
>> That's because you are mixing floating point and decimal.
>>
>> Just to take one example: double 1.1 cannot be represented
>> exactly as floating point and it's in fact
>> 1.10000002384185791015625.
>
> Sure. double has 53 mantissa bits but float only 24. But that
> is not my point.
> I am *not* talking about the 1e-18 but about these lines:
>
> 1.10 0.891207360061435339970703
> 0.878166666666666700439167 -1e-02
> 1.20 0.932039085967226349689098
> 0.932735999999999982229600 1e-04
> 1.30 0.963558185417192964729825
> 0.964774416666666678037840
> 1e-03
>
> and
>
> 5.70 -0.550685542597637763537807
> -25.165500000000002545915000 -
>
> At 5.7 the value is obviously out of range.
>
There was an error in 128/256 bit division. The exception might
be caused also by the same division since in the output values
are rounded also by division. I think now it's solved.
Now it prints:
1.00 +0.841470984807896506690000
+0.8414709848078965066525023216302990 +2.653e-18
1.10 +0.891207360061435339970000
+0.8912073600614353383642161528821827 +6.642e-19
1.20 +0.932039085967226349660000
+0.9320390859672263482207034175881317 +7.207e-19
1.30 +0.963558185417192964750000
+0.9635581854171929634976039012289115 +1.998e-18
1.40 +0.985449729988460180680000
+0.9854497299884601806594745788060975 +2.659e-18
1.50 +0.997494986604054430920000
+0.9974949866040544309417233711414873 +2.942e-18
1.60 +0.999573603041505164340000
+0.9995736030415051644881114370526778 +2.988e-18
1.70 +0.991664810452468615300000
+0.9916648104524686161192003644210237 +3.119e-18
1.80 +0.973847630878195186490000
+0.9738476308781951865323731788433576 +2.532e-18
1.90 +0.946300087687414488450000
+0.9463000876874144907527365796794817 +4.753e-18
2.00 +0.909297426825681695360000
+0.9092974268256816953960198659117448 +2.896e-18
2.10 +0.863209366648873770580000
+0.8632093666488737742146820454680267 +5.515e-18
2.20 +0.808496403819590184280000
+0.8084964038195901884235447312035390 +6.724e-18
2.30 +0.745705212176720177430000
+0.7457052121767201827156143818820931 +7.216e-18
2.40 +0.675463180551150926640000
+0.6754631805511509324649212496712473 +7.965e-18
2.50 +0.598472144103956494230000
+0.5984721441039565012621472421085657 +8.762e-18
2.60 +0.515501371821464235500000
+0.5155013718214642429697257155298933 +8.470e-18
2.70 +0.427379880233829934900000
+0.4273798802338299426927023640114310 +8.893e-18
2.80 +0.334988150155904919980000
+0.3349881501559049280238548187303455 +9.224e-18
2.90 +0.239249329213982328710000
+0.2392493292139823378938385702354806 +1.009e-17
3.00 +0.141120008059867222730000
+0.1411200080598672320006697688125648 +9.751e-18
3.10 +0.041580662433290579925000
+0.0415806624332905891860497743294677 +9.416e-18
3.20 -0.058374143427579908319000
-0.0583741434275798991542696566715643 +8.966e-18
3.30 -0.157745694143248381120000
-0.1577456941432483701618970386961038 +1.049e-17
3.40 -0.255541102026831318290000
-0.2555411020268313076483241184102069 +9.852e-18
3.50 -0.350783227689619847110000
-0.3507832276896198368828885525540795 +8.817e-18
3.60 -0.442520443294852383210000
-0.4425204432948523726088679351487828 +8.991e-18
3.70 -0.529836140908493212180000
-0.5298361409084932021854772134659022 +8.015e-18
3.80 -0.611857890942719074680000
-0.6118578909427190654510058312314653 +7.749e-18
3.90 -0.687766159183973817050000
-0.6877661591839738086537681707768678 +6.346e-18
4.00 -0.756802495307928250370000
-0.7568024953079282428752720232848741 +5.825e-18
4.10 -0.818277111064410503450000
-0.8182771110644104967923257194259585 +4.708e-18
4.20 -0.871575772413588059290000
-0.8715757724135880526646647777983275 +4.035e-18
4.30 -0.916165936749454983420000
-0.9161659367494549780197217790850059 +2.480e-18
4.40 -0.951602073889515953550000
-0.9516020738895159488107335437472529 +1.689e-18
4.50 -0.977530117665097054990000
-0.9775301176650970518056064241753746 -3.056e-19
4.60 -0.993691003633464455930000
-0.9936910036334644542315117020129026 -1.232e-18
4.70 -0.999923257564100884190000
-0.9999232575641008839565405992429380 -2.457e-18
4.80 -0.996164608835840671960000
-0.9961646088358406733565781684136726 -3.857e-18
4.90 -0.982452612624332512720000
-0.9824526126243325156335998995246860 -5.634e-18
5.00 -0.958924274663138469490000
-0.9589242746631384739990737444940666 -8.499e-18
5.10 -0.925814682327732297800000
-0.9258146823277323037497456163785133 -9.250e-18
5.20 -0.883454655720153265820000
-0.8834546557201532731063845238285883 -1.041e-17
5.30 -0.832267442223901164880000
-0.8322674422239011735432977190794839 -1.104e-17
5.40 -0.772764487555987363960000
-0.7727644875559873750523273015869194 -1.385e-17
5.50 -0.705540325570391908070000
-0.7055403255703919225313239842210499 -1.603e-17
5.60 -0.631266637872321313520000
-0.6312666378723213293016843594524164 -1.760e-17
5.70 -0.550685542597637763540000
-0.5506855425976377779216063046556619 -1.622e-17
5.80 -0.464602179413757213930000
-0.4646021794137572317851754163529263 -1.909e-17
5.90 -0.373876664830236362540000
-0.3738766648302363811468503760962045 -1.985e-17
6.00 -0.279415498198925875720000
-0.2794154981989258948954720395703132 -2.020e-17
>Chapter 9.2 of IEEE-754-2008 says the domain of sin(x) is (-inf,
>inf). So if the argument >x is outside the radius of convergence
>of the Taylor series x must be reduced modulo 2pi >such that it
>fits.
That's exactly how it's done internally:
https://github.com/rumbu13/decimal/blob/master/src/decimal/package.d#L13380
Your unity test also seems now to compute correctly. My maximum
|δ| for decimal128 is now 1e-34
>There's more to come (sorry for the greek symbols, could not
>resist to check this utf-8 feature)
I like them too:
https://github.com/rumbu13/decimal/blob/master/src/decimal/package.d#L13558
Do you have something against including parts of your test
published here as unittests? Thanks.
More information about the Digitalmars-d-announce
mailing list