Array Maximum Constant Expression Required Error - mql4

This error shows up when i try to find max array from these variables: Constant Expression Required. i've had a go, any ideas?
double num_array[3];
num_array[0]= RFTPD8;
num_array[1]= RFTPD7;
num_array[2]= RFS3;
double num_array[3]= {RFTPD8,RFTPD7,RFS3};
int maxValueIdx=ArrayMaximum(num_array,WHOLE_ARRAY,0);

Related

remove decimal from type double number but keep type double

double num = 333.5;
I need to the keep the type double but remove the decimal part of a number. Currently I'm
String numString = num.toStringAsFixed(0) (334)
which gets rid of the decimal. But I need to pass the number as a double. So I then
double.parse(numString) (334.0)
but this introduces the decimal again. Strange thing is... In dartpad the .0 (334)zero doesn't show which is desired. But in my environment the zero does show (334.0) .
Try this :
It's worked for me
num.round().toDouble(); ===>> (334)

why do I get this error although I have an operator in my code?

In MQL4, I have the following line
int OP_TYPE = int(0.5((1+f)*OP_BUY+(1-f)*OP_SELL));
which gives the error: '+' - some operator expected.
What am I supposed to do in this case?
You cannot infer calc types using MQL4, make sure you explicitly type your calculation in full.
int OP_TYPE = int(0.5*((1+f)*OP_BUY+(1-f)*OP_SELL));

Why can't I initialize a "const" variable with a primitive value received as a function argument in Dart?

I understand that, in Dart, primitives are passed by value and Objects are passed by reference.
So, I expected that
void test(String phrase) {
const _phrase = phrase;
}
would result in error, but
void test(int amount) {
const _amount = amount;
}
wouldn't.
However, both of them throws the same compile-time error: Const variables must be initialized with a constant value.
Is this some not implemented feature or there's a reason behind not accepting function arguments in const variables initialization?
Dart constant variables must be initialized with compile-time constant expressions.
A compile-time constant expression must always have the same value—precisely one value per source location.
Dart doesn't have "constant values" as such. It has constant expressions, which are known to evaluate to precisely one value, and for which it's possible to know this value at compile-time. That allows the compiler to canonicalize those constants values, so different constant expressions evaluating to constant objects with the same state are canonicalized to be the same object.
Your amount variable is not a compile-time constant expression. It can have different values at different times (because it's a function parameter and people might call the function with different arguments), so it cannot be a constant expression.
And therefore it cannot be used to initialize a constant variable, because constant variables can only have one value.
void test(int amount) {
const _amount = amount;
const list = [_amount]; // <- MUST ALWAYS HAVE SAME VALUE
}
In short: Dart constant variables must be initialized with a compile-time constant expression. A constant expression must always have the same value. This is the fundamental rule about Dart constant expressions which most other restrictions are derived from. (For example, a constant variable being used is a constant expression, so it must always be bound to the same value, which is why it must be initialized with a constant expression.)
I believe the answer is that constants are fixed at compile time rather than run time so function arguments cannot be passed to them as the function only gets executed at runtime.
See also here for example https://stackoverflow.com/a/58877374
A final modifier instead of const would work however.
By the way a String is also a primitive I think. See here https://stackoverflow.com/a/58568542

DirectCompute shader: how to get rid of warning X3205: 'round'

In a compute shader model 5, I have the result of some computation in a double precision floting point value. I have to assign the value to an integer variable and I get the warning:
warning X3205: 'round': conversion from larger type to smaller, possible loss of data
I understand the warning but in my case, at runtime the floating point value will never exceed the value acceptable for an integer. The code produce the expected result so I want to shut off that warning for the specific offending line.
I don't find how to turn off specific warning and I like to write code that do not produce any warning or if they are, they are checked to see if they are false alarm or not.
Any help appreciated.
You did not supply your code, and I suppose it was something in the form of:
double doubleValue = 1.0;
int integer = round(doubleValue);
If you want to suppress the warning, and you are sure the data you are dealing with will not give funny results, you can cast the double to a float before passing it to round().
double doubleValue = 1.0;
int integer = round((float)doubleValue);
This form does not trigger the warning.

Invalid Floating point operation using round(double) in Delphi

I am using Delphi 7, where I have variable v: double which is set to value 5,5889002873e+22 .
CurrencyDecimals is 2
When I use round(v), I get this error:
Invalid Floating point operation
It is not clear to me why it happens because range of double is exponent -308 to +308 . How to perform the rounding to be correct?
Result of Round is integer variable (help)
function Round(X: Real): Int64;
but Int64 type cannot contain values more than 2^63 - 1 (about 9*10^18), so
If the rounded value of X is not within the Int64 range, a run-time error is generated
What is a purpose of this rounding?

Resources