563 lines
33 KiB
MQL5
563 lines
33 KiB
MQL5
|
|
#ifndef LIB_MATH_SIMPLE_MQH_INCLUDED
|
||
|
|
#define LIB_MATH_SIMPLE_MQH_INCLUDED
|
||
|
|
#property version "1.9";
|
||
|
|
/**********************************************************************************
|
||
|
|
* Copyright (C) 2010-2022 Dominik Egert <info@freie-netze.de>
|
||
|
|
*
|
||
|
|
* This file is the simple math include file.
|
||
|
|
*
|
||
|
|
* MQLplus, including this file may not be copied and/or distributed
|
||
|
|
* without explecit permit by the author.
|
||
|
|
* Author Dominik Egert / Freie Netze UG.
|
||
|
|
**********************************************************************************
|
||
|
|
*
|
||
|
|
* Version: 1.9
|
||
|
|
* State: production
|
||
|
|
*
|
||
|
|
* File information
|
||
|
|
* ================
|
||
|
|
*
|
||
|
|
* Use: A collection of math functions
|
||
|
|
*
|
||
|
|
*
|
||
|
|
*
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
#ifdef DBG_MSG_TRACE_FILE_LOADER
|
||
|
|
DBG_MSG_TRACE_FILE_LOADER;
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/////////////////////////////////////////
|
||
|
|
//
|
||
|
|
// Set function shadowing mode
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifdef LIB_MQLPLUS_API_FUNCTION_SHADOWING
|
||
|
|
#define LIB_MATHSIMPLE_API_FUNCTION_SHADOWING
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef LIB_MQLPLUS_BINARY_LIBRARY
|
||
|
|
#define LIB_MATHSIMPLE_API_FORCE_DISABLE_FUNCTION_SHADOWING
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifdef LIB_MATHSIMPLE_API_FORCE_DISABLE_FUNCTION_SHADOWING
|
||
|
|
#ifdef LIB_MATHSIMPLE_API_FUNCTION_SHADOWING
|
||
|
|
#undef LIB_MATHSIMPLE_API_FUNCTION_SHADOWING
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/*********************************************************************************************************************************************************/
|
||
|
|
/* */
|
||
|
|
/* MQLplus math definitions */
|
||
|
|
/* */
|
||
|
|
/*********************************************************************************************************************************************************/
|
||
|
|
|
||
|
|
/////////////////////////////////////
|
||
|
|
//
|
||
|
|
// Math constants
|
||
|
|
//
|
||
|
|
|
||
|
|
#define M_CONST_M_GR 1.61803398874989484820458683436563811772030917980576286213544862270526046281890
|
||
|
|
#define M_CONST_M_DIV1_GR 0.61803398874989484820458683436563811772030917980576286213544862270526046281890
|
||
|
|
#define M_CONST_M_PHI M_CONST_M_GR
|
||
|
|
#define M_CONST_M_DIV1_PHI M_CONST_M_DIV1_GR
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/////////////////////////////////////
|
||
|
|
//
|
||
|
|
// Double and float macros
|
||
|
|
// and definitions
|
||
|
|
//
|
||
|
|
|
||
|
|
#define M_CONST_FLT_SNAN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_snan).f)
|
||
|
|
#define M_CONST_FLT_QNAN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_qnan).f)
|
||
|
|
#define M_CONST_FLT_NAN M_CONST_FLT_QNAN
|
||
|
|
#define M_CONST_FLT_INF_POS LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_inf_pos).f)
|
||
|
|
#define M_CONST_FLT_INF_NEG LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_inf_neg).f)
|
||
|
|
#define M_CONST_FLT_INF M_CONST_FLT_INF_POS
|
||
|
|
#define M_CONST_FLT_MIN_NEG LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_f_neg).f)
|
||
|
|
#define M_CONST_FLT_MAX_NEG -3.40282346638528859812e+38
|
||
|
|
#define M_CONST_DBL_INF_POS LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_inf_pos).d)
|
||
|
|
#define M_CONST_DBL_INF_NEG LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_inf_neg).d)
|
||
|
|
#define M_CONST_DBL_INF M_CONST_DBL_INF_POS
|
||
|
|
#define M_CONST_DBL_SNAN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_snan).d)
|
||
|
|
#define M_CONST_DBL_QNAN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_qnan).d)
|
||
|
|
#define M_CONST_DBL_NAN M_CONST_DBL_QNAN
|
||
|
|
#define M_CONST_DBL_MIN_NEG LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_f_neg).d)
|
||
|
|
#define M_CONST_DBL_MAX_NEG -1.79769313486231570815e+308
|
||
|
|
|
||
|
|
#define FLT_IS_SNAN(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_snan).ui)))
|
||
|
|
#define FLT_IS_QNAN(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_qnan).ui)))
|
||
|
|
#define FLT_IS_NAN(x) (FLT_IS_QNAN(x) || FLT_IS_SNAN(x))
|
||
|
|
#define FLT_IS_INF_POS(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_inf_pos).ui)))
|
||
|
|
#define FLT_IS_INF_NEG(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_inf_neg).ui)))
|
||
|
|
#define FLT_IS_INF(x) (FLT_IS_INF_POS(x) || FLT_IS_INF_NEG(x))
|
||
|
|
#define FLT_IS_NUMBER(x) (!(FLT_IS_NAN(x)) && !(FLT_IS_INF(x)))
|
||
|
|
#define DBL_IS_SNAN(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_snan).ul)))
|
||
|
|
#define DBL_IS_QNAN(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_qnan).ul)))
|
||
|
|
#define DBL_IS_NAN(x) (DBL_IS_QNAN(x) || DBL_IS_SNAN(x))
|
||
|
|
#define DBL_IS_INF_POS(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_inf_pos).ul)))
|
||
|
|
#define DBL_IS_INF_NEG(x) LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_cmp_invalid)(x, LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_inf_neg).ul)))
|
||
|
|
#define DBL_IS_INF(x) (DBL_IS_INF_POS(x) || DBL_IS_INF_NEG(x))
|
||
|
|
#define DBL_IS_NUMBER(x) (!(DBL_IS_NAN(x)) && !(DBL_IS_INF(x)))
|
||
|
|
|
||
|
|
#define M_CONST_MATH_NaN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_qnan).d)
|
||
|
|
#define M_CONST_MATH_INF LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_inf_pos).d)
|
||
|
|
#define M_CONST_FLT_NULL_P FLT_MIN
|
||
|
|
#define M_CONST_FLT_NULL_N LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, flt_f_neg).f)
|
||
|
|
#define M_CONST_DBL_NULL_P DBL_MIN
|
||
|
|
#define M_CONST_DBL_NULL_N LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, dbl_f_neg).d)
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/////////////////////////////////////
|
||
|
|
//
|
||
|
|
// Additional definitions
|
||
|
|
//
|
||
|
|
|
||
|
|
#define CHAR_MAX_NEG CHAR_MIN
|
||
|
|
#define SHORT_MAX_NEG SHORT_MIN
|
||
|
|
#define INT_MAX_NEG INT_MIN
|
||
|
|
#define LONG_MAX_NEG LONG_MIN
|
||
|
|
#define _UI64_MAX LONG_MAX
|
||
|
|
#define _I64_MIN LONG_MAX_NEG
|
||
|
|
#define _UI32_MAX INT_MAX
|
||
|
|
#define _I32_MIN INT_MAX_NEG
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
//
|
||
|
|
// Simple macro substitutions
|
||
|
|
//
|
||
|
|
|
||
|
|
// Boolean evaluation
|
||
|
|
#define inline_BooleanInteger(x) ((x) ? 0x01 : NULL)
|
||
|
|
#define inline_BooleanFloat(x) ((x) ? 1.0 : NULL)
|
||
|
|
#define inline_BooleanDouble(x) ((x) ? 1.0 : NULL)
|
||
|
|
|
||
|
|
// MathMax
|
||
|
|
#define inline_MathMax(value1, value2) ((value1 > value2) ? value1 : value2)
|
||
|
|
|
||
|
|
// MathMin
|
||
|
|
#define inline_MathMin(value1, value2) ((value1 < value2) ? value1 : value2)
|
||
|
|
|
||
|
|
// MathMinNN not null
|
||
|
|
#define inline_MathMinNN(value1, value2) (((value1 < value2) && (value1 != NULL) ? value1 : ((value2 == NULL) ? value1 : value2)))
|
||
|
|
|
||
|
|
// MathRange()
|
||
|
|
#define inline_MathRange(v, x, y) ((v <= x) ? x : ((v >= y) ? y : v))
|
||
|
|
#define inline_MathRangeX(v, x, y) ((v < x) ? x : ((v > y) ? y : v))
|
||
|
|
|
||
|
|
// MathDigits
|
||
|
|
#define inline_MathDigits(value) ((int)(::MathRound(::MathAbs(::MathLog10((double)(value))))))
|
||
|
|
|
||
|
|
// MathAbs
|
||
|
|
#define inline_MathAbs(value) (value * ((value < NULL) ? -1 : 1))
|
||
|
|
|
||
|
|
// MathNeg
|
||
|
|
#define inline_MathNeg(value) (value * ((value > NULL) ? -1 : 1))
|
||
|
|
|
||
|
|
// Can given value be evaluated to be zero
|
||
|
|
#ifdef LIB_MQLPLUS_EMPTY_VALUE
|
||
|
|
#define inline_MathIsZeroDouble(value) (double)( ((value <= NULL_P) && (value >= NULL_N)) || (value == LIB_MQLPLUS_EMPTY_VALUE) || (value == EMPTY_VALUE) || (value == MATH_NaN) )
|
||
|
|
|
||
|
|
#else
|
||
|
|
#define inline_MathIsZeroDouble(value) (double)( ((value <= NULL_P) && (value >= NULL_N)) || (value == EMPTY_VALUE) || (value == MATH_NaN) )
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
// Can given value be evaluated to be zero
|
||
|
|
#ifdef LIB_MQLPLUS_EMPTY_VALUE
|
||
|
|
#define inline_MathIsZeroInteger(value) (ulong)(((long)value == (long)0x0000000000000000) || ((long)value == ((long)0x8000000000000000)) || ((ulong)value == (ulong)LIB_MQLPLUS_EMPTY_VALUE) || ((ulong)value == (ulong)EMPTY_VALUE))
|
||
|
|
|
||
|
|
#else
|
||
|
|
#define inline_MathIsZeroInteger(value) (ulong)(((long)value == (long)0x0000000000000000) || ((long)value == ((long)0x8000000000000000)) || ((ulong)value == (ulong)EMPTY_VALUE))
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
// RoundPow2
|
||
|
|
#define inline_MathRoundPow2(x) ( ( (((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) | ((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) >> 4)) \
|
||
|
|
| (((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) | ((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) >> 4)) >> 8)) \
|
||
|
|
| ( (( (((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) | ((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) >> 4)) \
|
||
|
|
| (((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) | ((((x - 1) | ((x - 1) >> 1)) | (((x - 1) | ((x - 1) >> 1)) >> 2)) >> 4)) >> 8)) >> 16)) + 1)
|
||
|
|
|
||
|
|
//
|
||
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////
|
||
|
|
//
|
||
|
|
// Include main code
|
||
|
|
//
|
||
|
|
#ifndef LIB_MQLPLUS_IMPORT_SHARED_LIBRARY
|
||
|
|
#include "math_simple/lib_math_simple_main.mqh"
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////
|
||
|
|
//
|
||
|
|
// Include math simple functions
|
||
|
|
//
|
||
|
|
#ifdef LIB_MQLPLUS_IMPORT_SHARED_LIBRARY
|
||
|
|
#include "math_simple/lib_math_simple_functions.mqh"
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////
|
||
|
|
//
|
||
|
|
// Include tpl extensions
|
||
|
|
//
|
||
|
|
#include "math_simple/lib_math_simple_tpl.mqh"
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/////////////////////////////////////
|
||
|
|
//
|
||
|
|
// Technical value definitions
|
||
|
|
//
|
||
|
|
|
||
|
|
#include <MQLplus/lib_structures/lib_unions.mqh>
|
||
|
|
|
||
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
||
|
|
namespace LIB_MQLPLUS_LIBRARY_PREFIX {
|
||
|
|
namespace numbers {
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
static const _32_bit LIB_NAMESPACE_DEF(numbers, flt_inf_neg) = (uint)0xFF800000;
|
||
|
|
static const _32_bit LIB_NAMESPACE_DEF(numbers, flt_inf_pos) = (uint)0x7F800000;
|
||
|
|
static const _32_bit LIB_NAMESPACE_DEF(numbers, flt_snan) = (uint)0xFF800001;
|
||
|
|
static const _32_bit LIB_NAMESPACE_DEF(numbers, flt_qnan) = (uint)0xFFC00001;
|
||
|
|
static const _32_bit LIB_NAMESPACE_DEF(numbers, flt_f_neg) = (uint)0x70000001;
|
||
|
|
static const _64_bit LIB_NAMESPACE_DEF(numbers, dbl_inf_neg) = (ulong)0xFFF0000000000000;
|
||
|
|
static const _64_bit LIB_NAMESPACE_DEF(numbers, dbl_inf_pos) = (ulong)0x7FF0000000000000;
|
||
|
|
static const _64_bit LIB_NAMESPACE_DEF(numbers, dbl_snan) = (ulong)0x7FF0000000000001;
|
||
|
|
static const _64_bit LIB_NAMESPACE_DEF(numbers, dbl_qnan) = (ulong)0x7FF8000000000001;
|
||
|
|
static const _64_bit LIB_NAMESPACE_DEF(numbers, dbl_f_neg) = (ulong)0x8010000000000000;
|
||
|
|
|
||
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
||
|
|
}; // END Namespace numbers
|
||
|
|
}; // END Namespace LIB_MQLPLUS_LIBRARY_PREFIX
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////
|
||
|
|
//
|
||
|
|
// Constants definitions
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifdef LIB_DEBUG
|
||
|
|
const static double M_GR = M_CONST_M_GR;
|
||
|
|
const static double M_DIV1_GR = M_CONST_M_DIV1_GR;
|
||
|
|
const static double M_PHI = M_CONST_M_PHI;
|
||
|
|
const static double M_DIV1_PHI = M_CONST_M_DIV1_PHI;
|
||
|
|
const static double FLT_SNAN = M_CONST_FLT_SNAN;
|
||
|
|
const static double FLT_QNAN = M_CONST_FLT_QNAN;
|
||
|
|
const static double FLT_NAN = M_CONST_FLT_NAN;
|
||
|
|
const static double FLT_INF_POS = M_CONST_FLT_INF_POS;
|
||
|
|
const static double FLT_INF_NEG = M_CONST_FLT_INF_NEG;
|
||
|
|
const static double FLT_INF = M_CONST_FLT_INF;
|
||
|
|
const static double FLT_MIN_NEG = M_CONST_FLT_MIN_NEG;
|
||
|
|
const static double FLT_MAX_NEG = M_CONST_FLT_MAX_NEG;
|
||
|
|
const static double DBL_INF_POS = M_CONST_DBL_INF_POS;
|
||
|
|
const static double DBL_INF_NEG = M_CONST_DBL_INF_NEG;
|
||
|
|
const static double DBL_INF = M_CONST_DBL_INF;
|
||
|
|
const static double DBL_SNAN = M_CONST_DBL_SNAN;
|
||
|
|
const static double DBL_QNAN = M_CONST_DBL_QNAN;
|
||
|
|
const static double DBL_NAN = M_CONST_DBL_NAN;
|
||
|
|
const static double DBL_MIN_NEG = M_CONST_DBL_MIN_NEG;
|
||
|
|
const static double DBL_MAX_NEG = M_CONST_DBL_MAX_NEG;
|
||
|
|
const static double MATH_NaN = M_CONST_MATH_NaN;
|
||
|
|
const static double MATH_INF = M_CONST_MATH_INF;
|
||
|
|
const static double FLT_NULL_P = M_CONST_FLT_NULL_P;
|
||
|
|
const static double FLT_NULL_N = M_CONST_FLT_NULL_N;
|
||
|
|
const static double DBL_NULL_P = M_CONST_DBL_NULL_P;
|
||
|
|
const static double DBL_NULL_N = M_CONST_DBL_NULL_N;
|
||
|
|
|
||
|
|
#else
|
||
|
|
#define M_GR M_CONST_M_GR
|
||
|
|
#define M_DIV1_GR M_CONST_M_DIV1_GR
|
||
|
|
#define M_PHI M_CONST_M_PHI
|
||
|
|
#define M_DIV1_PHI M_CONST_M_DIV1_PHI
|
||
|
|
#define FLT_SNAN M_CONST_FLT_SNAN
|
||
|
|
#define FLT_QNAN M_CONST_FLT_QNAN
|
||
|
|
#define FLT_NAN M_CONST_FLT_NAN
|
||
|
|
#define FLT_INF_POS M_CONST_FLT_INF_POS
|
||
|
|
#define FLT_INF_NEG M_CONST_FLT_INF_NEG
|
||
|
|
#define FLT_INF M_CONST_FLT_INF
|
||
|
|
#define FLT_MIN_NEG M_CONST_FLT_MIN_NEG
|
||
|
|
#define FLT_MAX_NEG M_CONST_FLT_MAX_NEG
|
||
|
|
#define DBL_INF_POS M_CONST_DBL_INF_POS
|
||
|
|
#define DBL_INF_NEG M_CONST_DBL_INF_NEG
|
||
|
|
#define DBL_INF M_CONST_DBL_INF
|
||
|
|
#define DBL_SNAN M_CONST_DBL_SNAN
|
||
|
|
#define DBL_QNAN M_CONST_DBL_QNAN
|
||
|
|
#define DBL_NAN M_CONST_DBL_NAN
|
||
|
|
#define DBL_MIN_NEG M_CONST_DBL_MIN_NEG
|
||
|
|
#define DBL_MAX_NEG M_CONST_DBL_MAX_NEG
|
||
|
|
#define MATH_NaN M_CONST_MATH_NaN
|
||
|
|
#define MATH_INF M_CONST_MATH_INF
|
||
|
|
#define FLT_NULL_P M_CONST_FLT_NULL_P
|
||
|
|
#define FLT_NULL_N M_CONST_FLT_NULL_N
|
||
|
|
#define DBL_NULL_P M_CONST_DBL_NULL_P
|
||
|
|
#define DBL_NULL_N M_CONST_DBL_NULL_N
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////
|
||
|
|
//
|
||
|
|
// Setup function macros
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifdef LIB_MATHSIMPLE_API_FUNCTION_SHADOWING
|
||
|
|
#ifdef MathMax
|
||
|
|
#undef MathMax
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathMin
|
||
|
|
#undef MathMin
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathPow
|
||
|
|
#undef MathPow
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathAbs
|
||
|
|
#undef MathAbs
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathRound
|
||
|
|
#undef MathRound
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathCeil
|
||
|
|
#undef MathCeil
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathFloor
|
||
|
|
#undef MathFloor
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#ifdef MathRand
|
||
|
|
#undef MathRand
|
||
|
|
|
||
|
|
#endif
|
||
|
|
#define MathMax LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathMax))
|
||
|
|
#define MathMin LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathMin))
|
||
|
|
#define MathPow LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathPow))
|
||
|
|
#define MathAbs LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathAbs))
|
||
|
|
#define MathRound LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRound))
|
||
|
|
#define MathCeil LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))
|
||
|
|
#define MathFloor LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))
|
||
|
|
#define MathRand LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRand))
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#define MathMinNN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathMinNN))
|
||
|
|
#define MathRoot LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRoot))
|
||
|
|
#define MathRange LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRange))
|
||
|
|
#define MathRangeX LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRangeX))
|
||
|
|
#define MathRangeMatch LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRangeMatch))
|
||
|
|
#define MathRangeOverlap LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRangeOverlap))
|
||
|
|
#define MathDigits LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathDigits))
|
||
|
|
#define MathNeg LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathNeg))
|
||
|
|
#define MathRandN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRandN))
|
||
|
|
//#define MathRandX LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRandX))
|
||
|
|
#define MathZero LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathZero))
|
||
|
|
#define MathGreaterThan LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathGreaterThan))
|
||
|
|
#define MathLessThan LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathLessThan))
|
||
|
|
#define MathCompare LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCompare))
|
||
|
|
#define MathRoundPow2 LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRoundPow2))
|
||
|
|
#define MathFiboLevel LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFiboLevel))
|
||
|
|
#define MathUID LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathUID))
|
||
|
|
#define RTCdeltaMilliseconds LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_RTCdeltaMilliseconds))
|
||
|
|
#define RTCdeltaMicroseconds LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_RTCdeltaMicroseconds))
|
||
|
|
|
||
|
|
|
||
|
|
#ifdef LIB_MQLPLUS_IMPORT_SHARED_LIBRARY
|
||
|
|
#define mqp_MathMinNN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathMinNN))
|
||
|
|
#define mqp_MathRoot LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRoot))
|
||
|
|
#define mqp_MathRange LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRange))
|
||
|
|
#define mqp_MathRangeX LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRangeX))
|
||
|
|
#define mqp_MathRangeMatch LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRangeMatch))
|
||
|
|
#define mqp_MathRangeOverlap LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRangeOverlap))
|
||
|
|
#define mqp_MathDigits LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathDigits))
|
||
|
|
#define mqp_MathNeg LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathNeg))
|
||
|
|
#define mqp_MathRandN LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRandN))
|
||
|
|
#define mqp_MathRandX LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRandX))
|
||
|
|
#define mqp_MathZero LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathZero))
|
||
|
|
#define mqp_MathGreaterThan LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathGreaterThan))
|
||
|
|
#define mqp_MathLessThan LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathLessThan))
|
||
|
|
#define mqp_MathCompare LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCompare))
|
||
|
|
#define mqp_MathRoundPow2 LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRoundPow2))
|
||
|
|
#define mqp_MathFiboLevel LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFiboLevel))
|
||
|
|
#define mqp_MathUID LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathUID))
|
||
|
|
#define mqp_RTCdeltaMilliseconds LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_RTCdeltaMilliseconds))
|
||
|
|
#define mqp_RTCdeltaMicroseconds LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_RTCdeltaMicroseconds))
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//////////////////////////////////
|
||
|
|
//
|
||
|
|
// Unit test function
|
||
|
|
//
|
||
|
|
void unit_test_math_simple()
|
||
|
|
{
|
||
|
|
#ifdef LIB_MATHSIMPLE_API_FUNCTION_SHADOWING
|
||
|
|
printf("MathMax(1, 20, 5) %-40s", StringFormat("= %i", MathMax(1, 20, 5) ));
|
||
|
|
printf("MathMin(1, 20, 4) %-40s", StringFormat("= %i", MathMin(1, 20, 4) ));
|
||
|
|
printf("MathPow(10, 2) %-40s", StringFormat("= %i", MathPow(10, 2) ));
|
||
|
|
printf("MathAbs(-1) %-40s", StringFormat("= %i", MathAbs(-1) ));
|
||
|
|
printf("MathRound(4) %-40s", StringFormat("= %i", MathRound(4) ));
|
||
|
|
printf("MathCeil(11, 0) %-40s", StringFormat("= %i", MathCeil(11, 0) ));
|
||
|
|
printf("MathFloor(26, 0) %-40s", StringFormat("= %i", MathFloor(26, 0) ));
|
||
|
|
uchar arr_A[];
|
||
|
|
MathRand(arr_A ,5);
|
||
|
|
printf("MathRand(arr_A ,5)");
|
||
|
|
ArrayPrint(arr_A);
|
||
|
|
|
||
|
|
#else
|
||
|
|
printf("MathMax(1.0, 20.0) %-40s", StringFormat("= %f", MathMax(1.0, 20.0) ));
|
||
|
|
printf("MathMin(1.0, 20.0) %-40s", StringFormat("= %f", MathMin(1.0, 20.0) ));
|
||
|
|
printf("MathPow(10.0, 2.0) %-40s", StringFormat("= %f", MathPow(10.0, 2.0) ));
|
||
|
|
printf("MathAbs(-1.0) %-40s", StringFormat("= %f", MathAbs(-1.0) ));
|
||
|
|
printf("MathRound(4.5) %-40s", StringFormat("= %f", MathRound(4.5) ));
|
||
|
|
printf("MathCeil(1.987654321) %-40s", StringFormat("= %f", MathCeil(1.987654321) ));
|
||
|
|
printf("MathFloor(2.123456789) %-40s", StringFormat("= %f", MathFloor(2.123456789) ));
|
||
|
|
printf("MathRand() %-40s", StringFormat("= %f", MathRand() ));
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
printf("mqp_MathMax(1, 20, 5) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathMax))(1, 20, 5) ));
|
||
|
|
printf("mqp_MathMin(1, 20, 4) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathMin))(1, 20, 4) ));
|
||
|
|
printf("mqp_MathPow(10, 2) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathPow))(10, 2) ));
|
||
|
|
printf("mqp_MathAbs(-1) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathAbs))(-1) ));
|
||
|
|
printf("mqp_MathRound(4) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRound))(4) ));
|
||
|
|
printf("mqp_MathRound(6) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRound))(6) ));
|
||
|
|
printf("mqp_MathCeil(11, 2) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11, 2) ));
|
||
|
|
printf("mqp_MathFloor(26, 2) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(26, 2) ));
|
||
|
|
|
||
|
|
printf("mqp_MathCeil(11.5432, 2) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11.5432, 2)));
|
||
|
|
printf("mqp_MathCeil(11.5432, 1) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11.5432, 1)));
|
||
|
|
printf("mqp_MathCeil(11.4321, 1) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11.4321, 1)));
|
||
|
|
printf("mqp_MathCeil(11.4321, 0) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11.4321, 0)));
|
||
|
|
printf("mqp_MathCeil(11, -1) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11, -1) ));
|
||
|
|
printf("mqp_MathCeil(11, -2) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathCeil))(11, -2) ));
|
||
|
|
|
||
|
|
printf("mqp_MathFloor(11.5432, 2) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(11.5432, 2)));
|
||
|
|
printf("mqp_MathFloor(11.5432, 1) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(11.5432, 1)));
|
||
|
|
printf("mqp_MathFloor(11.4321, 1) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(11.4321, 1)));
|
||
|
|
printf("mqp_MathFloor(11.4321, 0) %-40s", StringFormat("= %f", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(11.4321, 0)));
|
||
|
|
printf("mqp_MathFloor(11, -1) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(11, -1) ));
|
||
|
|
printf("mqp_MathFloor(11, -2) %-40s", StringFormat("= %i", LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathFloor))(11, -2) ));
|
||
|
|
|
||
|
|
uchar arr_B[];
|
||
|
|
LIB_NAMESPACE_ADD(LIB_NAMESPACE(numbers, _mqlplus_MathRand))(arr_B ,5);
|
||
|
|
printf("mqp_MathRand(arr_B ,5)");
|
||
|
|
ArrayPrint(arr_B);
|
||
|
|
|
||
|
|
printf("MathMinNN(3.0, 2.0, NULL) %-40s", StringFormat("= %f", MathMinNN(3.0, 2.0, NULL) ));
|
||
|
|
printf("MathRoot(9.0, 2.0) %-40s", StringFormat("= %f", MathRoot(9.0, 2.0) ));
|
||
|
|
printf("MathRange(2.5, 1.0, 3.0) %-40s", StringFormat("= %f", MathRange(2.5, 1.0, 3.0) ));
|
||
|
|
bool in_range = false;
|
||
|
|
printf("MathRangeX(2.5, 2.5, 1) %-40s", StringFormat("= %f; in range: %i", MathRangeX(2.5, 2.5, 1, in_range), in_range ));
|
||
|
|
printf("MathRangeMatch(1.0, 2.0, 1.5, 2.5) %-40s", StringFormat("= %i", MathRangeMatch(1.0, 2.0, 1.5, 2.5) ));
|
||
|
|
printf("MathRangeMatch(1.0, 2.0, 2.0, 2.5) %-40s", StringFormat("= %i", MathRangeMatch(1.0, 2.0, 2.0, 2.5) ));
|
||
|
|
printf("MathRangeOverlap(1.0, 2.0, 1.5, 2.5) %-40s", StringFormat("= %f", MathRangeOverlap(1.0, 2.0, 1.5, 2.5) ));
|
||
|
|
printf("MathRangeOverlap(1.0, 2.0, 2.0, 2.5) %-40s", StringFormat("= %f", MathRangeOverlap(1.0, 2.0, 2.0, 2.5) ));
|
||
|
|
printf("MathDigits(0.001) %-40s", StringFormat("= %f", MathDigits(0.001) ));
|
||
|
|
printf("MathNeg(4.5) %-40s", StringFormat("= %f", MathNeg(4.5) ));
|
||
|
|
printf("MathZero(NULL) %-40s", StringFormat("= %i", MathZero(0.0) ));
|
||
|
|
printf("MathZero(DBL_MIN) %-40s", StringFormat("= %i", MathZero(DBL_MIN) ));
|
||
|
|
printf("MathGreaterThan(3.0, 2.0, 2.1, 2.3, 2.5) %-40s", StringFormat("= %f", MathGreaterThan(3.0, 2.0, 2.1, 2.3, 2.5) ));
|
||
|
|
printf("MathLessThan(3.0, 2.0, 2.1, 2.3, 2.5) %-40s", StringFormat("= %f", MathLessThan(3.0, 2.0, 2.1, 2.3, 2.5) ));
|
||
|
|
|
||
|
|
printf("MathCompare(3.002, 3.004, 2) %-40s", StringFormat("= %i", MathCompare(3.004, 3.002, 2) ));
|
||
|
|
printf("MathCompare(3.004, 3.002, 3) %-40s", StringFormat("= %i", MathCompare(3.004, 3.002, 3) ));
|
||
|
|
printf("MathCompare(3.002, 3.003, 3) %-40s", StringFormat("= %i", MathCompare(3.002, 3.003, 3) ));
|
||
|
|
|
||
|
|
printf("MathRoundPow2(54) %-40s", StringFormat("= %f", MathRoundPow2(54) ));
|
||
|
|
|
||
|
|
printf("MathFiboLevel(10.0, true) %-40s", StringFormat("= %f", MathFiboLevel(10.0, true) ));
|
||
|
|
printf("MathFiboLevel(20.0, true) %-40s", StringFormat("= %f", MathFiboLevel(20.0, true) ));
|
||
|
|
printf("MathFiboLevel(30.0, true) %-40s", StringFormat("= %f", MathFiboLevel(30.0, true) ));
|
||
|
|
printf("MathFiboLevel(50.0, true) %-40s", StringFormat("= %f", MathFiboLevel(50.0, true) ));
|
||
|
|
printf("MathFiboLevel(90.0, true) %-40s", StringFormat("= %f", MathFiboLevel(90.0, true) ));
|
||
|
|
|
||
|
|
printf("MathFiboLevel(2) %-40s", StringFormat("= %f", MathFiboLevel(2) ));
|
||
|
|
printf("MathFiboLevel(3) %-40s", StringFormat("= %f", MathFiboLevel(3) ));
|
||
|
|
printf("MathFiboLevel(4) %-40s", StringFormat("= %f", MathFiboLevel(4) ));
|
||
|
|
printf("MathFiboLevel(5) %-40s", StringFormat("= %f", MathFiboLevel(5) ));
|
||
|
|
printf("MathFiboLevel(6) %-40s", StringFormat("= %f", MathFiboLevel(6) ));
|
||
|
|
|
||
|
|
printf("MathFiboLevel(7, 1.0, 2.0, false, true) %-40s", StringFormat("= %f", MathFiboLevel(7, 1.0, 2.0, false, true) ));
|
||
|
|
printf("MathFiboLevel(8, 1.0, 2.0, false, true) %-40s", StringFormat("= %f", MathFiboLevel(8, 1.0, 2.0, false, true) ));
|
||
|
|
printf("MathFiboLevel(9, 1.0, 2.0, false, true) %-40s", StringFormat("= %f", MathFiboLevel(9, 1.0, 2.0, false, true) ));
|
||
|
|
printf("MathFiboLevel(10, 1.0, 2.0, false, true) %-40s", StringFormat("= %f", MathFiboLevel(10, 1.0, 2.0, false, true) ));
|
||
|
|
printf("MathFiboLevel(11, 1.0, 2.0, false, true) %-40s", StringFormat("= %f", MathFiboLevel(11, 1.0, 2.0, false, true) ));
|
||
|
|
|
||
|
|
printf("MathFiboLevel(4, 2.0, 3.0, false, false) %-40s", StringFormat("= %f", MathFiboLevel(4, 1.0, 2.0, false, false) ));
|
||
|
|
printf("MathFiboLevel(5, 2.0, 3.0, false, false) %-40s", StringFormat("= %f", MathFiboLevel(5, 1.0, 2.0, false, false) ));
|
||
|
|
printf("MathFiboLevel(8, 2.0, 3.0, false, false) %-40s", StringFormat("= %f", MathFiboLevel(8, 1.0, 2.0, false, false) ));
|
||
|
|
printf("MathFiboLevel(9, 2.0, 3.0, false, false) %-40s", StringFormat("= %f", MathFiboLevel(9, 1.0, 2.0, false, false) ));
|
||
|
|
printf("MathFiboLevel(12, 2.0, 3.0, false, false) %-40s", StringFormat("= %f", MathFiboLevel(12, 1.0, 2.0, false, false) ));
|
||
|
|
|
||
|
|
printf("MathFiboLevel(4, 1.0, 1.5, true, false) %-40s", StringFormat("= %f", MathFiboLevel(4, 1.0, 1.5, true, false) ));
|
||
|
|
printf("MathFiboLevel(5, 1.0, 1.5, true, false) %-40s", StringFormat("= %f", MathFiboLevel(5, 1.0, 1.5, true, false) ));
|
||
|
|
printf("MathFiboLevel(8, 1.0, 1.5, true, false) %-40s", StringFormat("= %f", MathFiboLevel(8, 1.0, 1.5, true, false) ));
|
||
|
|
printf("MathFiboLevel(9, 1.0, 1.5, true, false) %-40s", StringFormat("= %f", MathFiboLevel(9, 1.0, 1.5, true, false) ));
|
||
|
|
printf("MathFiboLevel(12, 1.0, 1.5, true, false) %-40s", StringFormat("= %f", MathFiboLevel(12, 1.0, 1.5, true, false) ));
|
||
|
|
|
||
|
|
printf("MathUID() %-40s", StringFormat("= %llu", MathUID() ));
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//
|
||
|
|
// END Simple math functions */
|
||
|
|
//*********************************************************************************************************************************************************/
|
||
|
|
#endif // LIB_MATH_SIMPLE_MQH_INCLUDED
|