Forum > Beginners

floating point literals

<< < (2/7) > >>


--- Quote from: srvaldez on February 20, 2024, 02:48:09 pm ---in this case the compiler should be smart enough to treat the literals as double because the variable on the left is of type double

--- End quote ---
Afaik, every programming language goes bottom-up from the smallest Type the literal value fits in, irrespective what's left hand side of the equal-symbol.
The same with "evaluating" if it's a mathematical calculation: It takes the smallest fitting Datatype the result fits in, AND THEN checks if it fit's in/is compatibel to the Datatype left hand side.

The only way is to "hardcast" right hand side, and IIRC, at least one operand should be enough

--- 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";}};} ---Var d:Double;d:= Double(1.0)/3.0;

my question has not been answered, is there a post-fix symbol for number literals?
in C, 1.0 is treated as double, 1.0f is treated as single and similarly for integer types, L for signed 32-bit, UL for unsigned 32-bit and LL and ULL for 64-bit integers

Unfortunately no typed floating-point literals in Pascal.
The compiler is "smart" and chooses the type with the lowest bit width, where the value is representable.

You can apply the -CF64 compiler option to parse every floating-point literal as 64bit double.

Here is a more detailed explanation:

thanks explainedd  :)


--- Quote from: srvaldez on February 20, 2024, 03:59:11 pm ---thanks explainedd  :)

--- End quote ---
Or {$MINFPCONSTPREC 64} in your source.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version