Of course you're right. But I'll repeat. For 99.9% of tasks it is absolutely correct to replace rounding functions with alternative faster variant using conversion of fractional types to (int) or (long). An experienced programmer should be aware of this fact and apply it when it is expedient.
In 99% of cases there is no need to bother with rounding at all. For price comparisons I have this nonsense:
// 0 - first is greater than second// 1 - equal// 2 - second is greater than firstuchar compare_prices(double first, double second)
{
if(first - second >= _Point)
return0;
if(second - first >= _Point)
return2;
first = round(first/_Point);
second = round(second/_Point);
if(first > second)
return0;
if(first < second)
return2;
return1;
}
You may notice that in most cases it won't come to round() at all, although I haven't measured the speed.
at x=3 in both cases there will be an incorrect value of 4
and in case of variant:
is so far the most correct while maintaining maximum speed of execution.
but why do you need this formula when you give an integer to its input?
with respect.
P.S. you need to understand, if you want to be a good programmer, that not everywhere and not always you need to shove all sorts of accelerating functions, it depends on the task at hand and the algorithm you're working with.
P.S. You have to understand, if you want to be a good programmer, that not everywhere and not always you need to shove all sorts of accelerating functions, it depends on the task at hand and the algorithm you are working with.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Of course you're right. But I'll repeat. For 99.9% of tasks it is absolutely correct to replace rounding functions with alternative faster variant using conversion of fractional types to (int) or (long). An experienced programmer should be aware of this fact and apply it when it is expedient.
In 99% of cases there is no need to bother with rounding at all. For price comparisons I have this nonsense:
You may notice that in most cases it won't come to round() at all, although I haven't measured the speed.
see above
when x = 3 (any integer) there is a jam :))
Respectfully.
Is there a bug in mine or in your formula?
Respectfully.
In my old one:
and in yours:
when x=3 in both cases will be the wrong value of 4
and the variant:
is so far the most correct while maintaining maximum speed of execution.
In my old one:
and in yours:
at x=3 in both cases there will be an incorrect value of 4
and in case of variant:
is so far the most correct while maintaining maximum speed of execution.
but why do you need this formula when you give an integer to its input?
P.S. you need to understand, if you want to be a good programmer, that not everywhere and not always you need to shove all sorts of accelerating functions, it depends on the task at hand and the algorithm you're working with.with respect.
Why do you need this formula when you give an integer to its input?
Sincerely.
You may not know whether it is an integer or a non-integer. There are times when a double number can become an integer.
P.S. You have to understand, if you want to be a good programmer, that not everywhere and not always you need to shove all sorts of accelerating functions, it depends on the task at hand and the algorithm you are working with.
You may not know whether it is an integer or a non-integer. There are times when a number can become an integer.
Respectfully.
P.S. double by definition cannot be an integer, the representation of a number in machine memory will not change.Then you have to make a big deal about your choices of numbers on the input.
respectfully.
that's why, so we don't have to make a big deal out of it:
It's easier to write:
or this.
so you don't have to make a big deal out of it:
it's easier to write:
1-0.9999999999999998you won't get it right.
With this approach, you can find a number at which your formula will not work.
Respectfully.
at
It's not going to work.
With this approach, you'll find a number at which your formula won't work.
Respectfully.
I've already written about it here.
I suggest you reread this thread so you don't repeat yourself.