Quantcast

Floating point precision / guard digits? (PR#13771)

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Floating point precision / guard digits? (PR#13771)

rbugs09
Full_Name: D Kreil
Version: 2.8.1 and 2.9.0
OS: Debian Linux
Submission from: (NULL) (141.244.140.179)


Group: Accuracy

I understand that most floating point numbers are approximated due to their
binary storage. On the other hand, I thought that modern math CPUs used guard
digits to protect against trivial underflows. Not true?

# integers, no problem
> 1+1+1==3
[1] TRUE
# binary floating point approximation underflows
> .1+.1+.1==.3
[1] FALSE
> .1+.1+.1==.3
[1] FALSE
# binary floating point exact for certain numbers
> .1+.1==.2
[1] TRUE

I know that safe code should not test for quality of floats. Still, is R
underutilizing the power of the underlying hardware?

Grateful for comments,
David.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

macrakis
a) this is not a bug, so this is the wrong list

b) 'underflow' does not mean what you think it means.

c) guard digits and sticky bits do improve rounding behavior, but
floating point will always remain approximate.

d) if it is important to your application to perform exact arithmetic
on rational numbers (and I suspect it is not), you might want to use
that instead of floating-point. But even if implemented in R, most R
calculations cannot use it.

You may want to study up on floating-point arithmetic some more, though.

         -s

On 6/19/09, [hidden email] <[hidden email]> wrote:

> Full_Name: D Kreil
> Version: 2.8.1 and 2.9.0
> OS: Debian Linux
> Submission from: (NULL) (141.244.140.179)
>
>
> Group: Accuracy
>
> I understand that most floating point numbers are approximated due to their
> binary storage. On the other hand, I thought that modern math CPUs used
> guard
> digits to protect against trivial underflows. Not true?
>
> # integers, no problem
>> 1+1+1==3
> [1] TRUE
> # binary floating point approximation underflows
>> .1+.1+.1==.3
> [1] FALSE
>> .1+.1+.1==.3
> [1] FALSE
> # binary floating point exact for certain numbers
>> .1+.1==.2
> [1] TRUE
>
> I know that safe code should not test for quality of floats. Still, is R
> underutilizing the power of the underlying hardware?
>
> Grateful for comments,
> David.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

Dr. D. P. Kreil
Dear Stavros,

Thank you for your fast reply!

So if I request a calculation of "0.3-0.1-0.1-0.1" and I do not get 0,
that is not an issue of rounding / underflow (or whatever the correct
technical term would be for that behaviour)?

I thought that guard digits would mean that 0.3-0.1*31 should be
calculated in higher precision than the final representation of the
result, i.e., avoiding that this is not equal to 0?

I am sorry if I am not from the field and although I have had some
basic background in numerics that has been more than a decade ago. If
you can suggest an online resource to help me use the right vocabulary
and better understand the fundamental concepts, I am of course
grateful.

Best regards,
David.


2009/6/20 Stavros Macrakis <[hidden email]>:

> a) this is not a bug, so this is the wrong list
>
> b) 'underflow' does not mean what you think it means.
>
> c) guard digits and sticky bits do improve rounding behavior, but
> floating point will always remain approximate.
>
> d) if it is important to your application to perform exact arithmetic
> on rational numbers (and I suspect it is not), you might want to use
> that instead of floating-point. But even if implemented in R, most R
> calculations cannot use it.
>
> You may want to study up on floating-point arithmetic some more, though.
>
>         -s
>
> On 6/19/09, [hidden email] <[hidden email]> wrote:
>> Full_Name: D Kreil
>> Version: 2.8.1 and 2.9.0
>> OS: Debian Linux
>> Submission from: (NULL) (141.244.140.179)
>>
>>
>> Group: Accuracy
>>
>> I understand that most floating point numbers are approximated due to their
>> binary storage. On the other hand, I thought that modern math CPUs used
>> guard
>> digits to protect against trivial underflows. Not true?
>>
>> # integers, no problem
>>> 1+1+1==3
>> [1] TRUE
>> # binary floating point approximation underflows
>>> .1+.1+.1==.3
>> [1] FALSE
>>> .1+.1+.1==.3
>> [1] FALSE
>> # binary floating point exact for certain numbers
>>> .1+.1==.2
>> [1] TRUE
>>
>> I know that safe code should not test for quality of floats. Still, is R
>> underutilizing the power of the underlying hardware?
>>
>> Grateful for comments,
>> David.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

Liviu Andronic
On 6/20/09, Dr. D. P. Kreil <[hidden email]> wrote:
>  you can suggest an online resource to help me use the right vocabulary
>  and better understand the fundamental concepts, I am of course
>
There is in R the accuracy [1] package. It has a vignette (and paper)
dealing with various computational errors (in R).
Liviu

[1] http://cran.r-project.org/web/packages/accuracy/index.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

Liviu Andronic
In reply to this post by rbugs09
On 6/20/09, Dr. D. P. Kreil <[hidden email]> wrote:
>  you can suggest an online resource to help me use the right vocabulary
>  and better understand the fundamental concepts, I am of course
>
There is in R the accuracy [1] package. It has a vignette (and paper)
dealing with various computational errors (in R).
Liviu

[1] http://cran.r-project.org/web/packages/accuracy/index.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

Charles Geyer
In reply to this post by rbugs09
On Sat, 20 Jun 2009 08:44:21 -0400 Stavros Macrakis <[hidden email]>
wrote:

> d) if it is important to your application to perform exact arithmetic
> on rational numbers (and I suspect it is not), you might want to use
> that instead of floating-point. But even if implemented in R, most R
> calculations cannot use it.

Just for the record, the contributed package rcdd links the GMP (GNU
multiprecision bignum) library and provides a crude interface, so it
is "implemented in R", although, as you say, "most R calculations cannot
use it".  The rcdd package can do exact linear programming and other
computational geometry operations.

--
Charles Geyer
Professor, School of Statistics
University of Minnesota
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

Kasper Daniel Hansen
In reply to this post by Dr. D. P. Kreil

On Jun 20, 2009, at 6:45 , Dr. D. P. Kreil wrote:

> I am sorry if I am not from the field and although I have had some
> basic background in numerics that has been more than a decade ago. If
> you can suggest an online resource to help me use the right vocabulary
> and better understand the fundamental concepts, I am of course
> grateful.

Read the R FAQ 7.31. There is a reference there to a document you  
should read.

Kasper

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Floating point precision / guard digits? (PR#13771)

Dr. D. P. Kreil
In reply to this post by Liviu Andronic
Dear Liviu,

That's very helpful, thank you!

With best regards,
David

2009/6/22 Liviu Andronic <[hidden email]>:

> On 6/20/09, Dr. D. P. Kreil <[hidden email]> wrote:
>>  you can suggest an online resource to help me use the right vocabulary
>>  and better understand the fundamental concepts, I am of course
>>
> There is in R the accuracy [1] package. It has a vignette (and paper)
> dealing with various computational errors (in R).
> Liviu
>
> [1] http://cran.r-project.org/web/packages/accuracy/index.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Loading...