Forum > General

Evaluation of constant statements

**AlanTheBeast**:

--- 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 TFy = 0.95; TFx = 1 - TFy;

and later on

--- 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";}};} --- y := x * TFx; //or y := TFx * x;

When I read this it irks me from an algebra POV....

I don't get that warm and fuzzy feeling that (1-TFy) is operated separately before (or after) the multiplication.

**KodeZwerg**:

--- Quote from: AlanTheBeast on September 21, 2022, 04:20:26 pm ---

--- 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 TFy = 0.95; TFx = 1 - TFy;

--- End quote ---

--- 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 TFy = Double(0.95); TFx = Double(1 - TFy);Thats how I would write such to have a proper type set.

**KodeZwerg**:

--- Quote from: AlanTheBeast on September 21, 2022, 04:20:26 pm ---I don't get that warm and fuzzy feeling that (1-TFy) is operated separately before (or after) the multiplication.

--- End quote ---

The constant will be "calculated" at the point when you set it, at least that's how it should work.

**Thaddy**:

--- Quote from: AlanTheBeast on September 21, 2022, 04:20:26 pm ---

--- 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 TFy = 0.95; TFx = 1 - TFy;

and later on

--- 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";}};} --- y := x * TFx; //or y := TFx * x;

When I read this it irks me from an algebra POV....

I don't get that warm and fuzzy feeling that (1-TFy) is operated separately before (or after) the multiplication.

--- End quote ---

The compiler sticks to mathematical operator precedence. See the manual.

https://www.freepascal.org/docs-html/ref/ref.html#QQ2-151-184

The tables are listed in precedence order. Note ** is implemented by the programmer, it is listed at that position because ** is a special form of multiplication.

If you are not sure, you can indeed enclose a partial expression using ( and ) but carefully written code should not need that in all cases because of the above.

**440bx**:

--- Quote from: AlanTheBeast on September 21, 2022, 04:20:26 pm ---I don't get that warm and fuzzy feeling that (1-TFy) is operated separately before (or after) the multiplication.

--- End quote ---

true constants are evaluated at compile time, therefore the expression (1- TFy) doesn't exist past its declaration, what exists after its evaluation is its result.

Navigation

[0] Message Index

[#] Next page