Till now, I understand that I should replace the code with your optimized (!) function, then put a big warning for users to disable compiler optimizations before using the library, in order to get the same performance they would get without using all of this shit!
amrali #: Till now, I understand that I should replace the code with your optimized (!) function, then put a big warning for users to disable compiler optimizations before using the library, in order to get the same performance they would get without using all of this shit!
If, indeed, you have a desire to figure out how to correctly measure the performance of any functions, go to the Russian-language forum and ask there. The developers talked about it in detail with examples. I don't have any links.
//+------------------------------------------------------------------+//| Get number of fractional digits that agree after the decimal |//| point of two numbers. GetEqualDigits(3.124, 3.122) => 2 |//+------------------------------------------------------------------+int GetEqualDigits(constdouble a, constdouble b);
//+------------------------------------------------------------------+//| Get number of significant digits that agree of two numbers. |//| For example, GetEqualSignificantDigits(3.124, 3.122) => 3 |//+------------------------------------------------------------------+int GetEqualSignificantDigits(constdouble a, constdouble b);
Added miscellaneous functions:
//+------------------------------------------------------------------+//| Get number of significant digits. Significant digits or figures |//| is the sum of integer and decimal digits (left and right of the |//| decimal point), excluding leading and trailing zeros. |//| For example, the number 1.23 has 2 decimal places and 3 s.f. |//| Hint: Change number to scientific notation. It is easier to see. |//+------------------------------------------------------------------+int GetSignificantDigits(doublevalue);
//+------------------------------------------------------------------+//| Returns the exponent of the scientific notation of a number. |//| In scientific notation a number is converted to a decimal number |//| between 1.0 and 10, multiplied by 10 raised to some power. |//| It computes shift the decimal point to keep only one non-zero |//| digit before the decimal point. |//+------------------------------------------------------------------+int GetExponent10(constdoublevalue)l
//+------------------------------------------------------------------+//| Computes the sign of a value as 1, 0, -1 |//+------------------------------------------------------------------+double MathSign(constdoublevalue);
Added function for formatting of doubles to string:
//+------------------------------------------------------------------+//| Converting numeric value into a string in scientific notation |//| with one digit before the decimal point (e.g., 6.22e-23). |//| Digits : Optional. The number of digits after the decimal point. |//| Defaults to as many digits as necessary to represent the value. |//+------------------------------------------------------------------+string DoubleToExponential(constdoublevalue, int digits = -1);
//+------------------------------------------------------------------+//| Wrap a value between min (inclusive) and max (exclusive). |//+------------------------------------------------------------------+template<typename T>
T Wrap(const T value, const T min, const T max);
Renamed the rounding functions to Ceil(), Floor(), Round() and Trunc() to avoid name conflicts with <Math\Stat\Math.mqh>.
Fixed the GetDigits() function to avoid an infinite loop in rare situations.
These are three handy functions for comparison and rounding of floating-point numbers and formatting money:
1. `bool DoubleEquals(double x, double y, double eps)` compares two double values `x` and `y` with a given epsilon value `eps` and returns a boolean value indicating if they are equal within the given tolerance.
2. `double RoundTo(double value, int digits)` rounds a double value `value` to the given number of decimal `digits`.
3. `string FormatMoney(double amount)` formats a double value `amount` as a string representing a currency amount. It formats the amount with two decimal places, replaces the decimal point with a comma, and inserts spaces every three digits for readability. It also adds the currency symbol obtained from `AccountInfoString(ACCOUNT_CURRENCY)` at the end.
DoubleEquals(double x, double y, double eps) - This function compares two double values x and y with a tolerance eps . It returns true if x is within eps of y . This is useful for comparing floating-point numbers that may not be exactly equal due to rounding errors.
RoundTo(double value, int digits) - This function rounds a double value value to a specified number of decimal digits . It uses the MathRound() function to perform the rounding.
FormatMoney(double amount) - This function formats a double value amount as a string with currency symbols, commas for thousands separators, and two decimal places. It is useful for displaying monetary values in a user-friendly way.
string FormatMoney(double amount) {
string currency = AccountInfoString(ACCOUNT_CURRENCY);
string formatted = StringFormat("%.2f", amount);
formatted = StringReplace(formatted, ".", ",");
int len = StringLen(formatted);
for (int i = len - 6; i > 0; i -= 3) {
formatted = StringSubstr(formatted, 0, i) + " " + StringSubstr(formatted, i);
}
return formatted + " " + currency;
}
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.
fxsaber #:
You need to learn how to make proper performance measurements.
You are drawing wrong conclusions.
Unfortunately, you do not understand what you are measuring.
So, tell me what I do not understand please :-)
Till now, I understand that I should replace the code with your optimized (!) function, then put a big warning for users to disable compiler optimizations before using the library, in order to get the same performance they would get without using all of this shit!
If, indeed, you have a desire to figure out how to correctly measure the performance of any functions, go to the Russian-language forum and ask there. The developers talked about it in detail with examples. I don't have any links.
Update 1 March 2023
Added functions for comparison of doubles:
Added miscellaneous functions:
Added function for formatting of doubles to string:
Added new miscellaneous function.
The function has a much faster performance than MathPow(10, power).
Faster.
@fxsaber Thanks!
Forum on trading, automated trading systems and testing trading strategies
Libraries: Math Utils
amrali, 2023.03.08 15:32
Added new miscellaneous function.
The function has a much faster performance than MathPow(10, power).
Added faster rounding functions.
Update 24 April 2023
Added new function:
Renamed the rounding functions to Ceil(), Floor(), Round() and Trunc() to avoid name conflicts with <Math\Stat\Math.mqh>.
Fixed the GetDigits() function to avoid an infinite loop in rare situations.
3. `string FormatMoney(double amount)` formats a double value `amount` as a string representing a currency amount. It formats the amount with two decimal places, replaces the decimal point with a comma, and inserts spaces every three digits for readability. It also adds the currency symbol obtained from `AccountInfoString(ACCOUNT_CURRENCY)` at the end.
Post formatted by moderator