[GiNaC-list] Unwanted digits when performing arithmetic computations

Vladimir V. Kisil V.Kisil at leeds.ac.uk
Sat Oct 26 22:27:15 CEST 2024


	Hello,

	I think the inaccuracy is connected with standard float point
  arithmetic. If you will use instead the command:

    cout<<(numeric(1, 10)+numeric(7))<<endl;
    cout<<(numeric(1, 100)*numeric("9"))<<endl;
    cout<<(numeric(1, 100)*numeric("99"))<<endl;
    cout<<(numeric(1, 10)+numeric(7)).evalf()<<endl;
    cout<<(numeric(1, 100)*numeric("9")).evalf()<<endl;
    cout<<(numeric(1, 100)*numeric("99")).evalf()<<endl;

 you will get:

71/10
9/100
99/100
7.1
0.09
0.99

  Best wishes,
  Vladimir
-- 
Vladimir V. Kisil                  http://v-v-kisil.scienceontheweb.net
  Book:      Geometry of Mobius Maps       https://doi.org/10.1142/p835
  Soft:      Geometry of cycles         http://moebinv.sourceforge.net/
  Jupyter notebooks:        https://github.com/vvkisil?tab=repositories
>>>>> On Sat, 26 Oct 2024 21:08:13 +0530, "Dr. Mithun Bairagi" <bairagirasulpur at gmail.com> said:

    MB> Dear all ginac lovers, I have got some wrong results when
    MB> performing some simple computations using ginac.  I have
    MB> compiled and run the following c++ program using ginac-1.8.7,
    MB> cln-1.3.7 (mingw64 compiler, gcc version 14.2.0, windows 10 os),

    MB> #include <ginac/ginac.h>

    MB> using namespace std; using namespace GiNaC;

    MB> int main() { cout<<(numeric(0.1)+numeric(7))<<endl;
    MB> cout<<(numeric("0.01")*numeric("9"))<<endl;
    MB> cout<<(numeric("0.01")*numeric("99"))<<endl; }

    MB> the above program shows the following result:
    MB> 7.1000000000000000056 0.089999999999999999996
    MB> 0.98999999999999999995

    MB> I have got some unwanted digits which look very ugly. I think
    MB> the result should be 7.1 0.09 0.99


    MB> Best regards, Mithun Bairagi


More information about the GiNaC-list mailing list