Skip to content

Commit

Permalink
fix division logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oguyon committed Jan 22, 2025
1 parent 41f3d92 commit c5ca207
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 522 deletions.
750 changes: 243 additions & 507 deletions src/COREMOD_arith/execute_arith.c

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/COREMOD_arith/image_arith__im_f__im.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "imfunctions.h"
#include "mathfuncs.h"


int arith_image_cstfmod(const char *ID_name, double f1, const char *ID_out)
{
arith_image_function_1f_1(ID_name, f1, ID_out, &Pfmod);
Expand Down
3 changes: 0 additions & 3 deletions src/COREMOD_arith/image_arith__im_f_f__im.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
#include "imfunctions.h"
#include "mathfuncs.h"

// ==========================================
// Forward declaration(s)
// ==========================================

int arith_image_trunc(const char *ID_name,
double f1,
Expand Down
7 changes: 5 additions & 2 deletions src/COREMOD_arith/imfunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,9 @@ int arith_image_function_1f_1(const char *ID_name,
uint8_t datatype, datatypeout;
long i;


printf("%s [%d] f1=%f\n", __FILE__, __LINE__, f1);//TBE

ID = image_ID(ID_name);
datatype = data.image[ID].md[0].datatype;
naxis = data.image[ID].md[0].naxis;
Expand All @@ -2112,7 +2115,7 @@ int arith_image_function_1f_1(const char *ID_name,

for(i = 0; i < naxis; i++)
{
naxes[i] = data.image[ID].md[0].size[i];
naxes[i] = data.image[ID].md->size[i];
}

datatypeout = _DATATYPE_FLOAT;
Expand All @@ -2131,7 +2134,7 @@ int arith_image_function_1f_1(const char *ID_name,
&IDout);

free(naxes);
nelement = data.image[ID].md[0].nelement;
nelement = data.image[ID].md->nelement;

#ifdef _OPENMP
#pragma omp parallel if (nelement > OMP_NELEMENT_LIMIT)
Expand Down
9 changes: 1 addition & 8 deletions src/COREMOD_arith/mathfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,7 @@ double Pfmod(double a, double b)

double Ppow(double a, double b)
{
if(b > 0)
{
return ((double) pow(a, b));
}
else
{
return ((double) pow(a, -b));
}
return ((double) pow(a, b));
}

double Padd(double a, double b)
Expand Down
4 changes: 2 additions & 2 deletions src/CommandLineInterface/calc_bison.y
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ exps: TKNVAR {strcpy($$, $1); data.cmdargtoken[data.cmdNBarg].
| exps '/' exps {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_div($1, $3, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("image / image\n");}}
| exps '/' expd {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstdiv($1,(double) $3, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("image - double\n");}}
| exps '/' expl {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstdiv($1,(double) $3, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("image - long\n");}}
| expd '/' exps {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstdiv($3,(double) $1, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("double - image\n");}}
| expl '/' exps {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstdiv($3,(double) $1, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("long - image\n");}}
| expd '/' exps {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstdiv1($3,(double) $1, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("double - image\n");}}
| expl '/' exps {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstdiv1($3,(double) $1, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("long - image\n");}}
| exps '^' expl {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstpow($1,(double) $3, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("image^long\n");}}
| exps '^' expd {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_cstpow($1,(double) $3, calctmpimname); strcpy($$, calctmpimname); if(data.Debug>0){printf("image^double\n");}}
| TKFUNC_d_d exps ')' {snprintf(calctmpimname,200,"_tmpcalc%ld",data.calctmp_imindex); data.calctmp_imindex++; arith_image_function_im_im__d_d($2, calctmpimname, $1); strcpy($$, calctmpimname); if(data.Debug>0){printf("double_func(double)\n");}}
Expand Down

0 comments on commit c5ca207

Please sign in to comment.