diff --git a/CImg.h b/CImg.h index 553733e2..ca2a4df1 100644 --- a/CImg.h +++ b/CImg.h @@ -6907,12 +6907,23 @@ namespace cimg_library { return _fibonacci(n); // Not precise, but better than the wrong overflowing calculation } - //! Calculate greatest common divisor. - inline long gcd(long a, long b) { - while (a) { const long c = a; a = b%a; b = c; } + //! Calculate greatest common divisor of two integers. + template + inline T gcd(T a, T b) { + if (a<0) a = -a; + if (b<0) b = -b; + while (a) { const T c = a; a = b%a; b = c; } return b; } + //! Calculate least common multiple of two integers. + template + inline T lcm(T a, T b) { + if (a<0) a = -a; + if (!a && !b) return 0; + return a*(b/gcd(a,b)); + } + //! Convert character to lower case. inline char lowercase(const char x) { return (char)((x<'A'||x>'Z')?x:x - 'A' + 'a'); @@ -17261,13 +17272,22 @@ namespace cimg_library { if (!cimg::strcasecmp(s,"inf")) { val = cimg::type::inf(); nb = 1; } else if (!cimg::strcasecmp(s,"nan")) { val = cimg::type::nan(); nb = 1; } if (nb==1 && is_sth) val = -val; - } else if (*s=='0' && (s[1]=='x' || s[1]=='X')) { // Hexadecimal number + } else if (*s=='0' && (s[1]=='x' || s[1]=='X')) { // Hexadecimal litteral is_sth = *ss=='-'; if (cimg_sscanf(s + 2,"%x%c",&arg1,&sep)==1) { nb = 1; val = (double)arg1; if (is_sth) val = -val; } + } else if (*s=='0' && (s[1]=='b' || s[1]=='B')) { // Binary litteral + is_sth = *ss=='-'; + variable_name.assign(65); + if (cimg_sscanf(s + 2,"%64[01]%c",variable_name.data(),&sep)==1) { + nb = 1; + val = (double)std::strtol(variable_name,0,2); + } + if (is_sth) val = -val; + variable_name.assign(); } if (!nb) nb = cimg_sscanf(ss,"%lf%c%c",&val,&(sep=0),&(end=0)); if (nb==1) _cimg_mp_const_scalar(val); @@ -20918,18 +20938,6 @@ namespace cimg_library { _cimg_mp_scalar3(mp_gauss,arg1,arg2,arg3); } - if (!std::strncmp(ss,"gcd(",4)) { // Gcd - _cimg_mp_op("Function 'gcd()'"); - s1 = ss4; while (s1::vector((ulongT)op,pos,0).move_to(l_opcode); @@ -25759,7 +25767,26 @@ namespace cimg_library { #endif static double mp_gcd(_cimg_math_parser& mp) { - return cimg::gcd((long)_mp_arg(2),(long)_mp_arg(3)); + const unsigned int i_end = (unsigned int)mp.opcode[2]; + CImg values; + if (i_end==5) { // Only a single argument + if ((unsigned)mp.opcode[4]==1) return _mp_arg(3); // Real value + else values.assign(&_mp_arg(3),(unsigned int)mp.opcode[4]); // Vector value + } else if (i_end==7 && (unsigned int)mp.opcode[4]==1 && (unsigned int)mp.opcode[6]==1) // Two real arguments + return (double)cimg::gcd((cimg_int64)_mp_arg(3),(cimg_int64)_mp_arg(5)); + else { + unsigned int siz = 0; + for (unsigned int i = 4; i1) for (unsigned int k = 0; k values; + if (i_end==5) { // Only a single argument + if ((unsigned)mp.opcode[4]==1) return _mp_arg(3); // Real value + else values.assign(&_mp_arg(3),(unsigned int)mp.opcode[4]); // Vector value + } else if (i_end==7 && (unsigned int)mp.opcode[4]==1 && (unsigned int)mp.opcode[6]==1) // Two real arguments + return (double)cimg::lcm((cimg_int64)_mp_arg(3),(cimg_int64)_mp_arg(5)); + else { + unsigned int siz = 0; + for (unsigned int i = 4; i1) for (unsigned int k = 0; k>1) - 1))/2); } + //! Return greatest common diviser of all image values. + T gcd() const { + if (is_empty()) return 0; + const ulongT siz = size(); + longT res = (longT)*_data; + for (ulongT k = 1; k Logo

- Latest stable version: 3.3.3        Current pre-release: 3.3.4 (2024/02/07) + Latest stable version: 3.3.3        Current pre-release: 3.3.4 (2024/02/09)


diff --git a/html/header_doxygen.html b/html/header_doxygen.html index 50d00033..3a4aa3c3 100644 --- a/html/header_doxygen.html +++ b/html/header_doxygen.html @@ -26,7 +26,7 @@
Logo

- Latest stable version: 3.3.3        Current pre-release: 3.3.4 (2024/02/07) + Latest stable version: 3.3.3        Current pre-release: 3.3.4 (2024/02/09)