A Simple Matter of Conversion

Suppose you write a program that prints the value of the floating-point literal 0.1 in the programming language of your choice. Do you think it will actually print 0.1, or will it print something like 0.10000000000000001? Can you be confident in your answer without trying it? Suppose you print the value of a floating-point number and then copy that output into a program as a floating-point literal. Will the value of that literal be exactly equal to the floating-point number that you printed? Can you be confident in your answer without trying it? Surprisingly, the most useful answers to these questions have not only been understood for more than 20 years, but these answers have even been implemented efficiently, and made available free of charge. Nevertheless, most programmers do not even know that these solutions exist, and most programming-language implementations do not use them.


August 09, 2010
URL:http://www.drdobbs.com/architecture-and-design/a-simple-matter-of-conversion/228701443

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.