[Suggestion] Add in Math intrinsics
Added by Romain LE LAMER over 4 years ago
Hi,
I have a proposal for you, that of adding trunc(x,n)
where n is the desired number of digits.
The idea came to me because I need to find a correspondence.
The DataType of a classic grib seems to be P17
during my calculation with exprf
10u = ((10u > 0) ? 1 : -1) * (sqr(nint(sqrt(abs(10u * 230.4)))) / 230.4);
10v = ((10v > 0) ? 1 : -1) * (sqr(nint(sqrt(abs(10v * 230.4)))) / 230.4);
I have to set the DataType to
P24
to find an almost match.With
trunc(x,n)
I wouldn't have this problem and I would match 100% which would be very interesting ;)10u = trunc(((10u > 0) ? 1 : -1) * (sqr(nint(sqrt(abs(trunc(10u, 6) * 230.4)))) / 230.4), 6);
10v = trunc(((10v > 0) ? 1 : -1) * (sqr(nint(sqrt(abs(trunc(10v, 6) * 230.4)))) / 230.4), 6);
Replies (4)
RE: [Suggestion] Add in Math intrinsics - Added by Romain LE LAMER over 4 years ago
DataType F32
matches even better but weighs down the file even more ...
RE: [Suggestion] Add in Math intrinsics - Added by Ralf Mueller over 4 years ago
hi!
couldn't you use floor
or ceil
from libm
?
Another option could be to substract both fields and work with a threashold:
cdo -gtc,0.0001 -sub infile1 infile2 outfile
cheers
ralf
RE: [Suggestion] Add in Math intrinsics - Added by Ralf Mueller over 4 years ago
libm offers a trunc
which could be added to CDO's expr
opertator (https://www.gnu.org/software/libc/manual/html_node/Rounding-Functions.html)
But I am not sure, that is really does, what you want ...
RE: [Suggestion] Add in Math intrinsics - Added by Romain LE LAMER over 4 years ago
Hi Ralf,
Indeed you are right on 2 points:
- I can use floor (x * 1000000) / 1000000
to get the truncation of my value with 6 digits.
- The function trunc does not correspond to my expectations.
Thanks for the tip