//+------------------------------------------------------------------+ //| 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 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ namespace TSN { //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define BIGNUMERBYLEO_BITS_TO_LIMBS(v) ((v+63)>>6) #define BIGNUMERBYLEO_LIMBS_TO_BITS(v) (v<<6) //--- #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) //--- #define BIGNUMERBYLEO_MIN(A, B) ((A)>(B)?(B):(A)) #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) //--- #define BIGNUMERBYLEO_INITIAL_RESERVE (8) //--- #define BIGNUMERBYLEO_INITIAL_SIZE_ZERO (1) #define BIGNUMBERBYLEO_ZERO \ m_v_s = 1; \ m_v[0]=0ULL; //--- #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) //--- #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) //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // 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);\ } //------- // cualquier funcion que pueda producirr 0 #define BIGNUMBERSBYLEO_CLEAN_HIGH_ZEROS(_v, _vs) \ { \ while(_vs > 1 && _v[_vs - 1] == 0) \ _vs--; \ } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // Menos de 30 limbs finales (Entonces se usa school) #define BIGNUMBERBYLEO_MUL_SCHOL_TO_KARATSUBA (16) // Apartir en mas adlente se usa mas.. //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ #define BIGINTEGERBYLEO_ALLOC_V \ ulong v[];\ ArrayResize(v, vs);\ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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 }; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // 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 }; //+------------------------------------------------------------------+ //| BigUInteger::ToBytes* y FromBytes* | //+------------------------------------------------------------------+ //--- #define BIGUINTEGER_TOBYTES_DEFAULTK (-1) #define BIGUINTEGER_TOBYTES_EXACTK (-2) //--- #define BIGUINTEGER_LOADBYTES_BE (1) #define BIGUINTEGER_LOADBYTES_LE (-1) } //+------------------------------------------------------------------+ #endif // BIGNUMBERSBYLEO_SRC_BASE_DEF_MQH