Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concat function (WIP) #338

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion CImg.h
Original file line number Diff line number Diff line change
Expand Up @@ -22127,7 +22127,8 @@ namespace cimg_library_suffixed {
!std::strncmp(ss,"prod(",5) ||
!std::strncmp(ss,"argmin(",7) || !std::strncmp(ss,"argmax(",7) ||
!std::strncmp(ss,"argminabs(",10) || !std::strncmp(ss,"argmaxabs(",10) ||
!std::strncmp(ss,"argkth(",7)) { // Multi-argument functions
!std::strncmp(ss,"argkth(",7) ||
!std::strncmp(ss,"concat(",7)) { // Multi-argument functions
_cimg_mp_op(*ss=='a'?(ss[1]=='v'?"Function 'avg()'":
ss[3]=='k'?"Function 'argkth()'":
ss[4]=='i' && ss[6]=='('?"Function 'argmin()'":
Expand All @@ -22138,6 +22139,7 @@ namespace cimg_library_suffixed {
*ss=='k'?"Function 'kth()'":
*ss=='p'?"Function 'prod()'":
*ss=='v'?"Function 'var()'":
*ss=='c'?"Function 'concat()'":
ss[1]=='i'?(ss[3]=='('?"Function 'min()'":
"Function 'minabs()'"):
ss[1]=='a'?(ss[3]=='('?"Function 'max()'":
Expand All @@ -22152,6 +22154,7 @@ namespace cimg_library_suffixed {
*ss=='k'?mp_kth:
*ss=='p'?mp_prod:
*ss=='v'?mp_var:
*ss=='c'?mp_concat:
ss[1]=='i'?(ss[3]=='('?mp_min:mp_minabs):
ss[1]=='a'?(ss[3]=='('?mp_max:mp_maxabs):
mp_median;
Expand Down Expand Up @@ -23392,6 +23395,23 @@ namespace cimg_library_suffixed {
return val/(i_end - 3);
}

static double mp_concat(_cimg_math_parser& mp) {
const unsigned int i_end = (unsigned int)mp.opcode[2];
const unsigned int max_i_ind = i_end - 1;

double a = std::abs(_mp_arg(3));
bool use_neg = _mp_arg(3) < 0;

for (unsigned int i = 4; i < i_end; ++i) {
double b = std::abs(_mp_arg(i));
double num_digits = (double)(int)((b>1?std::log10(b):0) + 1);
a = i != max_i_ind ? (double)(int)(a * std::pow(10, num_digits) + b) : (double)(int)(a * std::pow(10, num_digits)) + b;
};

return use_neg ? -a : a;

}

static double mp_bitwise_and(_cimg_math_parser& mp) {
return (double)((longT)_mp_arg(2) & (longT)_mp_arg(3));
}
Expand Down