COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Retaining precision after subtraction

• Email
• Follow

```I've a simple question:

I have a script that calculates a p-value, which is often a tiny number (i.e. 1e-80).  I need the script to return the 1-p value but retain the precision.  When I try to do this, matlab always returns 1 for p-values below 1e-15.  Can anyone tell me how to retain the precision of the calculation ?

```
 0

See related articles to this posting

```"kevbrick Brick" <kevbric.k+spam@gmail.com> wrote in message <hr7ipk\$kbg\$1@fred.mathworks.com>...
> I've a simple question:
>
> I have a script that calculates a p-value, which is often a tiny number (i.e. 1e-80).  I need the script to return the 1-p value but retain the precision.  When I try to do this, matlab always returns 1 for p-values below 1e-15.  Can anyone tell me how to retain the precision of the calculation ?

help EPS

After you'll know why what you ask is not possible, unless you perform symbolic calculation.

Bruno
```
 0

```"kevbrick Brick" <kevbric.k+spam@gmail.com> wrote in message <hr7ipk\$kbg\$1@fred.mathworks.com>...
> I've a simple question:
>
> I have a script that calculates a p-value, which is often a tiny number (i.e. 1e-80).  I need the script to return the 1-p value but retain the precision.  When I try to do this, matlab always returns 1 for p-values below 1e-15.  Can anyone tell me how to retain the precision of the calculation ?
>
-----------
It is inherent in double precision floating point numbers that subtracting a number less than 2^(-54) (which is about 5.55e-17) from 1 will not change the 1.  Even with substantially larger numbers there would be a heavy loss of precision in such a subtraction.  You cannot have it otherwise if you use 'double' numbers.  You will have to make some alteration in your script to return just the p-value without subtracting it from 1 and alter your program that receives it accordingly.

The only alternative would be to deal with symbolic quantities that are capable of much higher accuracy perhaps using the 'vpa' facility.

Roger Stafford
```
 0

```kevbrick Brick wrote:
> I've a simple question:
>
> I have a script that calculates a p-value, which is often a tiny number
> (i.e. 1e-80).  I need the script to return the 1-p value but retain the
> precision.  When I try to do this, matlab always returns 1 for p-values
> below 1e-15.  Can anyone tell me how to retain the precision of the
> calculation ?

Besides the other response, I'd suspect that a probability estimate of
1E-80 is probably meaningless, anyway.

But, you could in the case in point generate the text result pretty
easily since it's the number of 9's of the exponent followed by the
remainder from 1.0 of p*1E(exp).  (Not that I think printing that out
will do anybody any good... :) )

--
```
 0