Forum > General

Why MaxDouble does not equal to MaxDouble?

(1/9) > >>

jollytall:
I have a simple program:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses Math;var d : double;begind := MaxDouble;writeln(d, ' ', MaxDouble, ' ', d = MaxDouble);end. The result is

--- Code: --- 1.7976931348623157E+308  1.79769313486231569996E+0308 FALSE

--- End code ---

Why is MaxDouble shown as E+0308, when even in the source it is defined as

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    const      { values according to        https://en.wikipedia.org/wiki/Double-precision_floating-point_format#Double-precision_examples      }      MinDouble    =  2.2250738585072014e-308;      MaxDouble    =  1.7976931348623157e+308;What is the best way to have a standard, built-in rarely used number to indicate that the number is not really used?

Warfley:
Thats the great thing about untyped constants, for floats they always are interpreted as extended. So when you put it into a double, it will get converted to double. When you than compare the double against the constant, the double will be promoted to extended. This double (pun intended) conversion creates rounding errors.

jollytall:
It is clear, but then I would consider it a bug. Shouldn't unit Math has it like:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const MaxDouble : double = 1.7976931348623157e+308;

Warfley:
This introduces a memory object (typed consts are objects in the executable, while untyped are just "macros" that are replaced by the compiler at compiletime), I think the correct way would be:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    const MaxDouble = Double(1.7976931348623157e+308);

jollytall:
Oh, yes, that's how it should be.

Navigation

[0] Message Index

[#] Next page

Go to full version