Giter VIP home page Giter VIP logo

bcd's People

Contributors

edwig avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sganz

bcd's Issues

Bugs in bcd::Exp

  1. bcd::Exp(0.0) should return 1;

Fix:
// Can not calculate: will always be zero
if(number.IsNull())
{
return bcd(1.0);
}

  1. bcd::Exp(-x) should return 1/(bcd::exp(x)) but code returns -bcd::Exp(x).

Fix:
// Take care of the sign
if(this->GetSign() < 0 )
{
result = 1.0/result;
}

std::string _afp_ftoa function returns wrong string

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);

Natural Log of 0.5 does not calculate properly

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.

cosine, sine and exp functions

afp versions of these functions evaluated at 0.0 goes into an infinite loop.

numeric::PI needs precision and scale arguments.

bug in bcd::Add => 0.0+(-0.05) is not equal to -0.05

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

bcd number representation or bcd::Exp is incorrect

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));

0.0 is not handled correctly boolean <

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;
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.