Alternative implementations of standard functions/approaches - page 7

 
pavlick_:

Because converting double to integer (this way) is shitty code. Round with friends is not designed to get integer type from floating type.

Well, who prevents you from changing the function type to double.
And control your speech, please.
 
Nikolai Semko:
Well, who's stopping you from changing the function type to double.
And control your speech, please.

No offence meant. There are all sorts of rint, lrint, llrint for conversion to integer. They did not just appear for a reason when it is much easier to do long(double). Converting floating to integer is a conceptual error.

 
pavlick_:

No offence meant. There are all sorts of rint, lrint, llrint to convert to integer. They were invented for a reason, when you can do a lot easier than long(double). Converting floating to integer is a conceptual error.

Oh, you're just out of the loop...
 
Nikolai Semko:
Oh, you're just out of touch...

OK, the UB is in your hands.

 
fxsaber:
Ambiguous interpretation then. Decided to output the cycle time, not the average time of one function call.

The gain is between 3 and 8 times.

Perhaps the method of calculating the time-to-function is not flawless, but it is quite objective. But if someone suggests a better, more unbiased method, that would be nice.

I changed it to type double for full analogy.

double Ceil (double x) { return double((x-(long)x>0)?(long)x+1:(long)x);}
double Round(double x) { return double((x>0)?(long)(x+0.5):(long)(x-0.5));}
double Floor(double x) { return double((x>0)?(long)x:((long)x-x>0)?(long)x-1:(long)x);} 
2018.08.25 22:16:01.309 TestRound (EURUSD,M10)  Время цикла без округления = 1.315 наносекунд, сумма = 5249993749.98145962
2018.08.25 22:16:01.309 TestRound (EURUSD,M10)  Время выполнения функции sqrt = 0.628 наносекунд, сумма = 81969849.90928555  // даже квадратный корень вычисляется в несколько раз быстрее чем штатные функции округления
2018.08.25 22:16:01.313 TestRound (EURUSD,M10)  Время выполнения функции ceil =  2.037 наносекунд, Контрольная сумма = 5250492895.0
2018.08.25 22:16:01.315 TestRound (EURUSD,M10)  Время выполнения функции Ceil =  0.587 наносекунд, Контрольная сумма = 5250492895.0
2018.08.25 22:16:01.318 TestRound (EURUSD,M10)  Время выполнения функции floor = 2.247 наносекунд, Контрольная сумма = 5249492896.0
2018.08.25 22:16:01.320 TestRound (EURUSD,M10)  Время выполнения функции Floor = 0.385 наносекунд, Контрольная сумма = 5249492896.0
2018.08.25 22:16:01.323 TestRound (EURUSD,M10)  Время выполнения функции round = 1.610 наносекунд, Контрольная сумма = 5249992896.0
2018.08.25 22:16:01.324 TestRound (EURUSD,M10)  Время выполнения функции Round = 0.181 наносекунд, Контрольная сумма = 5249992896.0

I suggest that the developers use this algorithm in regular functions.

Files:
TestRound.mq5  7 kb
 
)). This may have a place only in personal crafts with exact knowledge of the value range, but not in std library. The built-in functions are not written by fools, don't think you're the smartest. Here is a friend who also writes undefined and unspecified behavior and then is surprised that it does not work that way https://www.linux.org.ru/forum/development/14422428#comments. All these savings of several nanoseconds will not even be visible in real algorithm (not in naked loop).
 

I don't understand why rounding functions should return double either. In my opinion, that's the point of rounding - you need to define how to get an integer from a floating value.

What "conceptual error" of conversion is not quite clear to me either.

 
Georgiy Merts:

I don't understand why rounding functions should return double either. In my opinion, that's the point of rounding - you need to define how to get an integer from a floating value.

What "conceptual error" of conversion is not quite clear to me either.

Think about what you get outside of an integer.
 
fxsaber:

NormalizeDouble

The result is 1123275 and 1666643 in favour of MyNormalizeDouble (Optimize=1). Without optimization it is four times faster (in memory).


I always wanted to ask you if there is much you can program in your code style.

If you have a task to design and create a very complex mechanism by yourself, is it worth using your way of writing code? And you must check the performance of each record at every step.

How much time will it take a developer to read/write/verify the code, if you approach this process in your style and at your level?

I bet I'd grow old without writing even half of what I had in mind.


zy. Sorry about the offtops. Programming style is a personal matter. But at a certain point, you start to realize that code should be as readable as possible, precisely for productivity purposes.

Productivity - США - MetaTrader 5
Productivity - США - MetaTrader 5
  • www.metatrader5.com
Индекс производительности труда показывает изменение объема выпущенной продукции, приходящегося на одного работника. Этот показатель полезен для предсказания инфляции и прироста объема производства. Если стоимость труда увеличивается соответственно увеличению производительности, и, кроме того, маловероятно увеличение производственных издержек...
 
Реter Konow:

I've always wanted to ask you - how much can you program in your style of code?

An example of my style?

Reason: