Does Rascal have a shorthand for integer max value or real max value? - rascal

Is there a shorthand in Rascal to get the max integer value?
e.g. in Java's Integer.MAX_VALUE, or C#'s Int32.MaxValue

Rascal does not have a maximum integer value; It just grows until you are out of memory.

Related

zig print float precision

In zig it is possible to print float values in decimal notation by using "{d}". This will automatically print the value at full precision. Is there way to specify the number of digits? Either for each value, or as some kind of global setting?
This will limit the number of digits after the decimal point, with rounding and zero-padding:
format(w, "{d:.1}", .{0.05}) == "0.1"
format(w, "{d:.3}", .{0.05}) == "0.050"
More info

What will be the answer to these 2 variables? and what are the differences between the both?

double num1 = 0.0000012345.toStringAsPrecision(15);
double num2 = 0.0000012345.toStringAsFixed(15);
First is first, you can't store a String object into a double variable, these two functions will return you a String object.
You should check on dart documentation, there you'll able to find out the answers for your question.
toStringAsPrecission:
Converts this to a double and returns a string representation with exactly precision significant digits.
The parameter precision must be an integer satisfying: 1 <= precision
<= 21.
toStringAsFixed:
Converts this to a double before computing the string representation.
If the absolute value of this is greater or equal to 10^21 then this methods returns an exponential representation computed by this.toStringAsExponential(). Otherwise the result is the closest string representation with exactly fractionDigits digits after the decimal point. If fractionDigits equals 0 then the decimal point is omitted.
The parameter fractionDigits must be an integer satisfying: 0 <= fractionDigits <= 20.

single, double and precision

I know that storing single value (or double) can not be very precise. so storing for example 125.12 can result in 125.1200074788. now in delphi their is some usefull function like samevalue or comparevalue that take an epsilon as param and say that 125.1200074788 or for exemple 125.1200087952 is equal.
but i often see in code stuff like : if aSingleVar = 0 then ... and this in fact as i see always work. why ? why storing for exemple 0 in a single var keep the exact value ?
Only values that are in form m*2^e, where m and e are integers can be stored in a floating point variable (not all of them though, it depends on precision). 0 has this form, and 125.12 does not, as it equals 3128/25, and 1/25 is not an integer power of 2.
Comparing 125.12 to a single (or double) precision variable will most probably return always False, because a literal 125.12 will be treated as an extended precision number, and no single (or double) precision number would have such a value.
Looks like a good use for the BigDecimals unit by Rudy Velthuis. Millions of decimal places of accuracy and precision.

Is that a bug, when I send zero to to funtion luaO_ceillog2?

I'a reading lua source code which version is 5.3. And i found the function
int luaO_ceillog2 (unsigned int x) in lobject.c file doest't take a special discuss for 0. When 0 was send to this fuction, it would return 32. Does this is a bug? I was confused.
luaO_ceillog2 is a function that's only used internally. Its name infers that it calculates ceil (maximum number that's not less than) of log2 of the argument.
Mathematically, logbx is only valid for x who is positive. So 0 is not a valid argument for this function, I don't think this counts as a bug.

Big number and lost of precision

I do this operation and I want result without exponents :
main(){
var result = ((1.1+2)+3.14+4+(5+6+7)+(8+9+10)*4267387833344334647677634)/2*553344300034334349999000;
print(result); // With exponent
print(result.toInt()); // Full number ?
}
And it print
3.18780189038289e+49
31878018903828901761984975061078744643351263313920
But the toInt() result is wrong, the good result is 31878018903828899277492024491376690701584023926880 . It check it with groovy (web) console.
How can I do to have my int full number ?
As in result there are double literals, the result type is double.
In Dart a double is a :
64-bit (double-precision) floating-point numbers, as specified by the IEEE 754 standard
This is why you lose precision.
You can see the lost of precision with the following code :
final bignum = 31878018903828899277492024491376690701584023926880;
print(bignum);
// displays 31878018903828899277492024491376690701584023926880
print(bignum.toDouble().toInt());
// displays 31878018903828901761984975061078744643351263313920
This lost of precision is not specific to Dart, for instance 31878018903828899277492024491376690701584023926880.0 and 31878018903828901761984975061078744643351263313920.0 are equal in Java.
The groovy web console gives you the right result because AFAICT groovy literals with decimal points are instantiated as java.math.BigDecimal by default.
Finally there is an open issue on Decimal data type you can star and until decimals are natively supported, you can use my decimal package;

Resources