<div dir="ltr"><div>If I remember correctly, the arithmetic is done with floating 64b numbers, right? Doing bitwise operations there sound a bit (pun intended) strange.</div><div>I know a bit portion of images used are RGB (byte images), there bitwise operatios are fine.</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, 3 Dec 2025 at 21:14, Even Rouault via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<p>I see there's a <a>mu::ParserInt</a> class in
<a href="https://github.com/beltoforion/muparser/blob/master/include/muParserInt.h" target="_blank">https://github.com/beltoforion/muparser/blob/master/include/muParserInt.h</a>
, that we don't use in GDAL. A bit strange it wasn't mentionned in
[1]. Perhaps because of this comment: "This version of the parser
handles only integer numbers. It disables the built in operators
thus it is slower than muParser. Integer values are stored in the
double value_type and converted if needed."</p>
<div>Le 03/12/2025 à 21:07, Daniel Baston
via gdal-dev a écrit :<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div>Hugh,</div>
<div><br>
</div>
<div>My read of this discussion [1] is that bitwise operators
are not supported and we would need to add them as a GDAL
extension. This is pretty easy to do: see [2].
Alternatively, bitwise operators are probably supported by
the ExprTk expression parser [3] (supported by GDAL) or this
pull request [4].</div>
<div><br>
</div>
<div>Dan</div>
<div><br>
</div>
<div>[1] <a href="https://github.com/beltoforion/muparser/discussions/154#discussioncomment-13104418" target="_blank">https://github.com/beltoforion/muparser/discussions/154#discussioncomment-13104418</a></div>
<div>[2] <a href="https://github.com/OSGeo/gdal/pull/13187/files" target="_blank">https://github.com/OSGeo/gdal/pull/13187/files</a></div>
<div>[3] <a href="https://www.partow.net/programming/exprtk/" target="_blank">https://www.partow.net/programming/exprtk/</a> </div>
</div>
[4] <a href="https://github.com/OSGeo/gdal/pull/13470" target="_blank">https://github.com/OSGeo/gdal/pull/13470</a></div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Dec 3, 2025 at 2:58 PM
Hugh Graham via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div dir="ltr">Hi, <br>
<br>
I am using VRT muparser expressions for bitwise operations
when creating masks and wanted to understand why I can't
get the <i>bitwise & </i>operator working? My
current solution is to use fmod which is fine (and I think
equivalent) but using "&" would be convenient and a
bit easier to read...<br>
<br>
To illustrate, the following file works: <br>
<a href="https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-fmodmask-vrt" target="_blank">https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-fmodmask-vrt</a> <br>
the expression used here is:"(fmod(Fmask, 16) >= 8) ||
(fmod(Fmask, 8) >= 4) ? 0 : 1"<br>
<br>
```<br>
gdal convert "/vsicurl/<a href="https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-fmodmask.vrt" target="_blank">https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-fmodmask.vrt</a>"
"test.tif"<br>
```<br>
<br>
However, the following file fails: <br>
<a href="https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-bitmask-vrt" target="_blank">https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-bitmask-vrt</a><br>
the expression parsed as: "((Fmask & 8) > 0
|| (Fmask & 4) > 0) ? 0 : 1" in the XML but
provided as (to my xml parser):<br>
<br>
"((Fmask & 8) > 0 || (Fmask & 4) > 0) ? 0 :
1"<br>
<div><br>
</div>
<div>```</div>
<div>gdal convert "/vsicurl/<a href="https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-bitmask.vrt" target="_blank">https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-bitmask.vrt</a>"
"test.tif"<br>
0...10...20..ERROR 1: Unexpected token "& 8) > 0
|| (Fmask & 4) > 0) ? 0 : 1 " found at position
8.</div>
<div>``` <br>
<br>
So, is using "&" possible, or should I just stick
with fmod and not worry about it?<br>
<br>
Any help would be much appreciated. <br>
<br>
Hugh<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</div>
</div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
gdal-dev mailing list
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre cols="72">--
<a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div>