# 10.0014 + 0.0000123456 = 10.0014?

**URL:** <https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461>\
**Category:** General Discussion\
**Created:** [August 31, 2024, 2:28pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461 "2024-08-31T14:28:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanweiwei](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@hanweiwei](https://community.freefem.org/u/hanweiwei)\
**Post date:** [August 31, 2024, 2:28pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/1 "2024-08-31T14:28:01Z")

</div>

Hi everyone,

I have a question, for example.  
we define real a = 10.0014 and real b = 0.0000123456  
then we compute a+b by using FreeFem  
we obtain a+b = 10.0014, however the ture is 10.0014123456

so how can we avoid such error during the use of FreeFem. I encounter such error. if t = 10.0014 and dt = 0.0000123456, then the time step cannt be moved into a new time.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [August 31, 2024, 2:31pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/2 "2024-08-31T14:31:10Z")

</div>

I get `10.0014123456`.

---

<div class="post-metadata">

**Author:** ![hanweiwei](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@hanweiwei](https://community.freefem.org/u/hanweiwei)\
**Post date:** [August 31, 2024, 3:23pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/3 "2024-08-31T15:23:21Z")

</div>

![error](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5d93c67f8b96db06e95a790f046c8cb1f75da1b7.png)

Hi, thanks for your replying. I run the code, and obtian 10.0012

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [August 31, 2024, 3:30pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/4 "2024-08-31T15:30:49Z")

</div>

You are not using a high enough precision for `cout`.

---

<div class="post-metadata">

**Author:** ![hanweiwei](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@hanweiwei](https://community.freefem.org/u/hanweiwei)\
**Post date:** [August 31, 2024, 3:40pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/5 "2024-08-31T15:40:01Z")

</div>

Hi, thanks a lot.  
i define real d = 10.0012 and find that d != c. So when performing operations, you mean the real value of c is 10.0012123456 not 10.0012 ?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [August 31, 2024, 3:42pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/6 "2024-08-31T15:42:03Z")

</div>

Yes, that is correct.

---

<div class="post-metadata">

**Author:** ![hanweiwei](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@hanweiwei](https://community.freefem.org/u/hanweiwei)\
**Post date:** [August 31, 2024, 3:49pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/7 "2024-08-31T15:49:07Z")

</div>

Thanks again for your explanation. I get it and need to consider other direction to correct my code.

---

<div class="post-metadata">

**Author:** ![vlaude](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/vlaude/32/939_2.png) [@vlaude](https://community.freefem.org/u/vlaude)\
**Post date:** [September 1, 2024, 9:12am UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/8 "2024-09-01T09:12:03Z")

</div>

Please see [Freefem default precision](https://community.freefem.org/t/freefem-default-precision/2223)

```auto
real a=10.0012;
real b=0.0000123456;
cout << a+b << endl;
cout.precision(16);
cout << a+b << endl;

```

---

<div class="post-metadata">

**Author:** ![hanweiwei](https://avatars.discourse-cdn.com/v4/letter/h/bbe5ce/32.png) [@hanweiwei](https://community.freefem.org/u/hanweiwei)\
**Post date:** [September 1, 2024, 2:46pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/9 "2024-09-01T14:46:55Z")

</div>

Hi, thanks for your replying. I get it.

---

<div class="post-metadata">

**Author:** ![alh](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/alh/32/2354_2.png) [@alh](https://community.freefem.org/u/alh)\
**Post date:** [November 21, 2024, 2:13pm UTC](https://community.freefem.org/t/10-0014-0-0000123456-10-0014/3461/10 "2024-11-21T14:13:26Z")

</div>

In relation to this question, here is a way to check the internal precision used by FF on any platform

```auto
// integer size
// ------------

int i=1;
int n=1;

// Stop when the value is so big that it overflows into the sign bit

while(i>0){
  i*=2;
  n++;
}

cout<<"int size: "<<n<<endl;

// number of decimal places
// ------------------------

real e=1.;
real sum=1.+e;
n=0;

// Stop when the increment is so small that the sum does not change

while(sum!=1.){
  n++;
  e=e/10.;
  sum=1.+e;
}

cout<<"decimal digits: "<<n<<endl;

// maximum power of 10 in a floating-point number
// ----------------------------------------------

real a=1;
n=0;

// a becomes inf when the exponent is too big, so the test becomes inf==inf

while(a*10!=a){
  a*=10;
  n++;
}

cout<<"max exponent: "<<n-1<<endl;

```

[https://www.ljll.fr/lehyaric/ffcs/src/ffref/Basic/precision.m4.htm](https://www.ljll.fr/lehyaric/ffcs/src/ffref/Basic/precision.m4.htm)
