Page 1 of 1

possible bug -fx dealing with signed numbers

Posted: 2020-02-23T15:30:28-07:00
by fmw42
-fx used to be able to handle signed variables. But lately it fails when the variable's sign and the sign in the function are the same, e.g. a--b or a++b.

This change occurred between IM 6.9.10.83 and 6.9.10.84 (correspondingly between IM 6.9.10.84 and IM 7.0.9.14) and persists to the current versions 6.9.10.95 and 7.0.10.25.

Double Minus Sign fails

Code: Select all

xmax=492
xmin=-1
im691083 convert xc: -format "%[fx:abs($xmax-$xmin)]" info:
493
im691084 convert xc: -format "%[fx:abs($xmax-$xmin)]" info:
0 <--- WRONG
Minus and Plus Sign works fine:

Code: Select all

xmax=492
xmin=+1
im691083 convert xc: -format "%[fx:abs($xmax-$xmin)]" info:
491
im691084 convert xc: -format "%[fx:abs($xmax-$xmin)]" info:
491
Double Plus Sign fails

Code: Select all

xmax=492
xmin=+1
im691083 convert xc: -format "%[fx:abs($xmax+$xmin)]" info:
493
im691084 convert xc: -format "%[fx:abs($xmax+$xmin)]" info:
0 <--- WRONG
Running on Mac OSX Sierra.

Re: possible bug -fx dealing with signed numbers

Posted: 2020-02-23T16:36:55-07:00
by snibgo
There have been problems in the past with doubled signs in fx. To avoid the problems, if the second term may be negative, I put it in parentheses, eg:

Code: Select all

-format %[fx:10-(-2)]

Re: possible bug -fx dealing with signed numbers

Posted: 2020-02-23T16:42:32-07:00
by fmw42
Thanks. That seems to work on my Mac as well.

Re: possible bug -fx dealing with signed numbers

Posted: 2020-02-23T17:57:21-07:00
by magick
Parens work or put a space '$max - $min'. --/++ are decrement/increment operators. In the C language, for example, 6--7 or a--b both return syntax exceptions. Previously this worked because -fx did not support decrement/increment operators. However, we are expanding the language with better support for scripting.

Re: possible bug -fx dealing with signed numbers

Posted: 2020-02-23T20:05:51-07:00
by fmw42
magick wrote:put a space '$max - $min'
Spaces do not work on my Mac!

xmax=492
xmin=-1

Fails:
im691084 convert xc: -format "%[fx:abs($xmax-$xmin)]" info:
0

Works:
im691084 convert xc: -format "%[fx:abs($xmax-($xmin))]" info:
493


Fails
im691084 convert xc: -format "%[fx:abs($xmax - $xmin)]" info:
0

convert xc: -format "%[fx:abs($xmax - $xmin)]" info:
0



Spaces would be easier to use to edit my scripts. Is that a bug in -fx and if so is it possible to fix?


EDIT:

Oddly, it works with 2 spaces after the minus sign

Re: possible bug -fx dealing with signed numbers

Posted: 2020-02-24T05:14:09-07:00
by magick
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.