edwig / bcd Goto Github PK
View Code? Open in Web Editor NEWBinary Coded Decimal. Research project for use with SQL_NUMERIC_STRUCT datatype
License: MIT License
Binary Coded Decimal. Research project for use with SQL_NUMERIC_STRUCT datatype
License: MIT License
This calculation takes a long time.
Fix:
// Can not calculate: will always be zero
if(number.IsNull())
{
return bcd(1.0);
}
Fix:
// Take care of the sign
if(this->GetSign() < 0 )
{
result = 1.0/result;
}
Fix:
In icd::Exp() function
// Correcting the sign
if(this->GetSign() < 0 )
{
result = 1.0/result;
}
in lines 553 and 554 of Testing.cpp the values must be revered.
char* r_small_div = "1.5159130887395963684392407742872";
char* r_small_add = "2111111100999999.3343333322232221";
when afp object casted to double you get wrong value;
afp af = 30.0;
double daf = (double)af;
now daf is 3.0
Fix:
in afp.cpp lines 2159 should be:
// erase "." only if it is there
if (s[2]=='.')
s.erase(2,1);
When attempting to calculate
0.5^-1
the Power function uses natural logarithms. This failed to calculate 0.5 properly due to the check against epsilon not taking account
of the tussen being negative. I fixed it by adding an AbsoluteValue() call to tussen.
afp versions of these functions evaluated at 0.0 goes into an infinite loop.
numeric::PI needs precision and scale arguments.
following code produce:
bcd t1 = 0.0;
bcd t2 = -0.05;
bcd t3 = t1 + t2;
printf(" %g + (%g) = %g\n", t1.AsDouble(), t2.AsDouble(), t3.AsDouble());
bcd t4 = t2 + t1;
printf(" %g + (%g) = %g\n", t2.AsDouble(), t1.AsDouble(), t4.AsDouble());
output:
0 + (-0.05) = 9.95
-0.05 + (0) = 9.95
I make following fix:
bcd arg2(p_number);
// 0 + a = a
if (arg1.IsNull())
return arg2;
// a + 0 = a
if (arg2.IsNull())
return arg1;
PositionArguments(arg1, arg2, signResult, operatorKind);
output:
0 + (-0.05) = -0.05
-0.05 + (0) = -0.05
In my experiment I narrowed down to the exponential bcd::Exp function giving wrong answers.
bcd exp(0.01) is 1.010050167 Match
double ::exp(0.01) is 1.010050167
bcd exp(0.02) is 1.221402758 Do not match with ::exp
double ::exp(0.02) is 1.02020134
bcd exp(0.03) is 1.349858808 Do not match with ::exp
double ::exp(0.03) is 1.030454534
I think the problem is the bcd representation of .01, .02 and .03.
t = .1 + E-1 10000000 00000000 00000000 00000000 00000000
tt = .01 + E-2 10000000 00000000 00000000 00000000 00000000
t = .2 + E+0 02000000 00000000 00000000 00000000 00000000
tt = .02 + E-1 20000000 00000000 00000000 00000000 00000000
t = .3 + E+0 03000000 00000000 00000000 00000000 00000000
tt = .03 + E-1 30000000 00000000 00000000 00000000 00000000
Here is the code fragment for your convenience:
bcd t = 1 * .1;
t.DebugPrint("t = .1");
bcd tt = t / 10.;
tt.DebugPrint("tt = .01");
bcd bexp = exp(tt);
printf("bcd exp(0.01) is \t%20.10g\n", bexp.AsDouble());
printf("double ::exp(0.01) is \t%20.10g\n", ::exp(.01));
t = 2 * .1;
t.DebugPrint("t = .2");
tt = t / 10.;
tt.DebugPrint("tt = .02");
bexp = exp(tt);
printf("bcd exp(0.02) is \t%20.10g\n", bexp.AsDouble());
printf("double ::exp(0.02) is \t%20.10g\n", ::exp(.02));
t = 3 * .1;
t.DebugPrint("t = .3");
tt = t / 10.;
tt.DebugPrint("tt = .03");
bexp = exp(tt);
printf("bcd exp(0.03) is \t%20.10g\n", bexp.AsDouble());
printf("double ::exp(0.03) is \t%20.10g\n", ::exp(.03));
When the Taylor series is evaluated for functions such as sine arcsine tan arcTan the comparison to epsilon does not get evaluated correctly when number is 0.0 in bcd . Therefore, it goes into a infinite loop.
if (between.AbsoluteValue() < epsilon)
{
break;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.