2026-08-17 12:21:57 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Def.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza |
|
| | | //| https://www.mql5.com |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza"
|
| | | #property link "https://www.mql5.com"
|
| | | #property strict
|
| | |
|
| | | #ifndef BIGNUMBERSBYLEO_SRC_BASE_DEF_MQH
|
| | | #define BIGNUMBERSBYLEO_SRC_BASE_DEF_MQH
|
| | |
|
2026-08-17 17:30:57 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #include <TSN\\Tables\\DPairs.mqh>
|
2026-08-21 21:01:14 -05:00 | | | #include <TSN\\Tables\\Bits.mqh>
|
2026-08-17 17:30:57 -05:00 | | |
|
2026-08-17 12:21:57 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-09-07 21:55:02 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-09-09 20:01:20 -05:00 | | | #define BIGNUMERBYLEO_BITS_TO_LIMBS(v) ((v+63)>>6)
|
2026-09-07 21:55:02 -05:00 | | | #define BIGNUMERBYLEO_LIMBS_TO_BITS(v) (v<<6)
|
| | |
|
| | | //---
|
2026-09-10 09:23:17 -05:00 | | | #define BIGNUMERBYLEO_UINTEGER_IZ_PAR ((m_v[0]&1ULL)==0)
|
| | | #define BIGNUMERBYLEO_UINTEGER_IZ_ZERO (m_v_s == 1 && !m_v[0])
|
| | | #define BIGNUMERBYLEO_UINTEGER_IZ_NZERO (m_v_s > 1 || m_v[0]!=0)
|
2026-09-09 20:01:20 -05:00 | | |
|
| | | //---
|
2026-09-10 07:16:18 -05:00 | | | #define BIGNUMERBYLEO_MIN(A, B) ((A)>(B)?(B):(A))
|
2026-09-09 20:01:20 -05:00 | | | #define BIGNUMERBYLEO_ABS(V) ((V)>=0?(V):(-V))
|
| | | #define BIGNUMERBYLEO_SWAP(A, B, TTYPE) \
|
| | | { \
|
| | | const TTYPE _t = A; \
|
| | | A = B; \
|
| | | B = _t; \
|
| | | }
|
| | |
|
| | | //--- cmp
|
| | | #define BIGINTEGER_CMP_EQ (0)
|
| | | #define BIGINTEGER_CMP_MAYOR (1)
|
| | | #define BIGINTEGER_CMP_MENOR (2)
|
2026-09-07 21:55:02 -05:00 | | |
|
2026-09-10 07:16:18 -05:00 | | | //---
|
| | | #define BIGNUMERBYLEO_INITIAL_RESERVE (8)
|
| | |
|
| | | //---
|
2026-09-10 09:23:17 -05:00 | | | #define BIGNUMERBYLEO_INITIAL_SIZE_ZERO (1)
|
2026-09-10 07:16:18 -05:00 | | | #define BIGNUMBERBYLEO_ZERO \
|
2026-09-10 09:23:17 -05:00 | | | m_v_s = 1; \
|
2026-09-10 07:16:18 -05:00 | | | m_v[0]=0ULL;
|
| | |
|
2026-09-10 09:23:17 -05:00 | | | //---
|
| | | #define BIGNUMERBYLEO_INT_SNEG(S) \
|
| | | if(_nor_neg) \
|
| | | S = -S;
|
| | |
|
| | | #define BIGNUMERBYLEO_INT_NORMALIZE(S) \
|
| | | const bool _nor_neg = S < 0; \
|
| | | BIGNUMERBYLEO_INT_SNEG(S)
|
| | |
|
2026-09-10 08:11:32 -05:00 | | |
|
2026-09-12 09:37:07 -05:00 | | | //---
|
| | | #define NUMBERUTILS_MAX_VALUE_OFT_SIGNED(T) T((1ULL << ((sizeof(T) << 3)-1))-1)
|
| | | #define NUMBERUTILS_MAX_VALUE_OFT_USIGNED(T) ((NUMBERUTILS_MAX_VALUE_OFT_SIGNED(T) << 1) + 1)
|
| | |
|
| | |
|
2026-09-10 07:16:18 -05:00 | | |
|
2026-08-17 12:21:57 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | // inter
|
| | | // a b = A
|
| | | // c d = B
|
| | | // (ad) (bd)
|
| | | // (cb)
|
| | | // (ac)
|
| | | // inter es como el intermdio serian dos sumas sin carray y le sumas el carray que dejo
|
| | | // inter = (ad)(cb) + carry
|
| | | // lo = inter (solo tomoamos el valor raw no el carray) | (juntamos con lo)
|
| | | #define BIGNUMBERSBYLEO_MUL64(b, hi, lo) \
|
| | | {\
|
| | | const ulong b_lo = (uint)b;\
|
| | | const ulong b_hi = b >> 32;\
|
| | | const ulong lo_lo = a_lo * b_lo;\
|
| | | const ulong hi_lo = a_hi * b_lo;\
|
| | | const ulong lo_hi = a_lo * b_hi;\
|
| | | const ulong hi_hi = a_hi * b_hi;\
|
| | | const ulong inter = (lo_lo >> 32) + (uint)hi_lo + (uint)lo_hi;\
|
| | | lo = (inter << 32) | (uint)lo_lo;\
|
| | | hi = hi_hi + (hi_lo >> 32) + (lo_hi >> 32) + (inter >> 32);\
|
| | | }
|
2026-08-23 17:03:16 -05:00 | | |
|
2026-08-17 22:34:56 -05:00 | | | //-------
|
| | | // cualquier funcion que pueda producirr 0
|
2026-09-10 08:11:32 -05:00 | | | #define BIGNUMBERSBYLEO_CLEAN_HIGH_ZEROS(_v, _vs) \
|
2026-08-17 22:34:56 -05:00 | | | { \
|
2026-09-10 09:23:17 -05:00 | | | while(_vs > 1 && _v[_vs - 1] == 0) \
|
2026-09-10 08:11:32 -05:00 | | | _vs--; \
|
2026-08-17 22:34:56 -05:00 | | | }
|
| | |
|
2026-08-17 12:21:57 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | // Menos de 30 limbs finales (Entonces se usa school)
|
| | | #define BIGNUMBERBYLEO_MUL_SCHOL_TO_KARATSUBA (16)
|
| | | // Apartir en mas adlente se usa mas..
|
| | |
|
2026-08-22 14:12:43 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | #define BIGINTEGERBYLEO_ALLOC_V \
|
| | | ulong v[];\
|
| | | ArrayResize(v, vs);\
|
| | |
|
2026-09-10 08:11:32 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | enum ENUM_BIGNUMBERBYLEO_STR_BASE
|
| | | {
|
| | | BIGNUMBERBYLEO_STR_BASE_2 = 2,
|
| | | BIGNUMBERBYLEO_STR_BASE_3,
|
| | | BIGNUMBERBYLEO_STR_BASE_4,
|
| | | BIGNUMBERBYLEO_STR_BASE_5,
|
| | | BIGNUMBERBYLEO_STR_BASE_6,
|
| | | BIGNUMBERBYLEO_STR_BASE_7,
|
| | | BIGNUMBERBYLEO_STR_BASE_8,
|
| | | BIGNUMBERBYLEO_STR_BASE_9,
|
| | | BIGNUMBERBYLEO_STR_BASE_10
|
| | | };
|
| | |
|
2026-08-23 17:03:16 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | // numero de digitos maximo sin desopborar ulong que podiramso acomular por cada base en un chunk de clecutra de uns tr
|
| | | const int g_tsn_biguinteger_base_max[11]
|
| | | {
|
| | | -1, // 0
|
| | | -1, // 1
|
| | | 64, // 2
|
| | | 40,
|
| | | 32,
|
| | | 27,
|
| | | 24,
|
| | | 22,
|
| | | 21,
|
| | | 20,
|
| | | 19
|
| | | };
|
| | |
|
2026-08-23 17:38:27 -05:00 | | | //+------------------------------------------------------------------+
|
2026-08-27 10:22:04 -05:00 | | | //| BigUInteger::ToBytes* y FromBytes* |
|
2026-08-23 17:38:27 -05:00 | | | //+------------------------------------------------------------------+
|
2026-08-27 10:22:04 -05:00 | | | //---
|
2026-08-23 17:38:27 -05:00 | | | #define BIGUINTEGER_TOBYTES_DEFAULTK (-1)
|
2026-08-27 10:22:04 -05:00 | | | #define BIGUINTEGER_TOBYTES_EXACTK (-2)
|
| | |
|
| | | //---
|
2026-08-23 19:37:22 -05:00 | | | #define BIGUINTEGER_LOADBYTES_BE (1)
|
| | | #define BIGUINTEGER_LOADBYTES_LE (-1)
|
2026-08-23 17:03:16 -05:00 | | |
|
2026-08-17 12:21:57 -05:00 | | | }
|
| | | //+------------------------------------------------------------------+
|
2026-08-17 22:34:56 -05:00 | | | #endif // BIGNUMBERSBYLEO_SRC_BASE_DEF_MQH
|