possible bug -fx dealing with signed numbers

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug -fx dealing with signed numbers

Post 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.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: possible bug -fx dealing with signed numbers

Post 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)]
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -fx dealing with signed numbers

Post by fmw42 »

Thanks. That seems to work on my Mac as well.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -fx dealing with signed numbers

Post 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.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug -fx dealing with signed numbers

Post 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

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug -fx dealing with signed numbers

Post 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.

Locked