edwig / BCD

Binary Coded Decimal. Research project for use with SQL_NUMERIC_STRUCT datatype
MIT License
12 stars 1 forks source link

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

Closed sisirajaya closed 4 years ago

sisirajaya commented 4 years ago

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

sisirajaya commented 4 years ago

With the limited knowledge of the code, I made this fix to get around a possible bug in the code function. I am sure you will be able to make the proper fix. Sorry if I bother you!

sisirajaya commented 4 years ago

BTW, I am experimenting your code to solve higher order differential equation using 4-th order Runge Kutta algorithm. With these fixes I get the same answers for all data types, icd, bcd, afp and double.

Just thought you might like to know what I am doing with it.

edwig commented 4 years ago

Hi Sisirajaya,

Great to know. Awsome. Hope the BCD project is of service to you.

Try to fix every error you can find, as soon as I can.

Edwig.

Van: sisirajaya notifications@github.com Verzonden: dinsdag 10 maart 2020 18:52 Aan: edwig/BCD BCD@noreply.github.com CC: Subscribed subscribed@noreply.github.com Onderwerp: Re: [edwig/BCD] bug in bcd::Add => 0.0+(-0.05) is not equal to -0.05 (#6)

BTW, I am experimenting your code to solve higher order differential equation using 4-th order Runge Kutta algorithm. With these fixes I get the same answers for all data types, icd, bcd, afp and double.

Just thought you might like to know what I am doing with it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/edwig/BCD/issues/6?email_source=notifications&email_token=ABFDS32QBJTALL3ZP6NUNJLRGZ42TA5CNFSM4LFEHQPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMPACQ#issuecomment-597225482 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFDS364ATRU7OQQOWQFASLRGZ42TANCNFSM4LFEHQPA . https://github.com/notifications/beacon/ABFDS34OGM4RYDQWPQZAMV3RGZ42TA5CNFSM4LFEHQPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMPACQ.gif