octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #61968] pow2 with two arguments is not Matlab


From: Kai Torben Ohlhus
Subject: [Octave-bug-tracker] [bug #61968] pow2 with two arguments is not Matlab compatible
Date: Sat, 5 Feb 2022 05:28:24 -0500 (EST)

Follow-up Comment #14, bug #61968 (project octave):

Thanks again for the review @mmuetzel.

comment #12 and comment #13: Copyright, BIST pattern, and warning ID will
fixed.  Thanks for the hints.

comment #12 and comment #9:

> On many implementations, ldexp is less efficient than multiplication or
division by a power of two using arithmetic operators.

There must be a distinction.  pow2(x) with single argument calls exp2(x) or
pow(2,x) and is equal to "2.^x".  For (non-complex) double and float (single)
input we are even better now and pow2(x) calls the more specialized exp2(x)
function explicitly.

pow2(f,e) with two arguments calls ldexp.  This is documented Matlab behavior
(comment #0): discussions forbidden 😅

comment #9: More off-topic: Why are we using C functions (like ::exp) in many
cases instead of their corresponding C++ functions (like std::exp)?

Somehow in Octave the C symbols leak (intentionally?) into the C++ "octave::"
namespace.  I got hard errors using std::exp2, etc.

comment #12: "xelem" vs. "elem", etc., I reviewed the usages.  Sometimes it is
safer to call "elem" to ensure a unique data instance.  Input data structures
created outside the pow2 function are beyond the functions control (thinking
of race conditions in the future).

comment #12: Why not use `std::ldexp` in both cases (single and double
precision).

That is true, for C++ ldexpf does not exist and double/float overloads named
"ldexp" exist.

C no error: https://godbolt.org/z/GoTYGrWE5
C++ error: https://godbolt.org/z/n4r7xxrfc

The wiki reference is a little misleading:

https://en.cppreference.com/w/cpp/numeric/math/ldexp
https://en.cppreference.com/w/c/numeric/math/ldexp

As I am calling C functions, I try avoid implicit float->double typecasts and
call the respective function:

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/ieee754/flt-32/s_scalbnf.c;h=d521d9a3035d572c43454ac17ea5477c8f2b18d7;hb=refs/heads/master

https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/ieee754/dbl-64/s_scalbn.c;h=4491227f3e3b5cf431564146b4aadc9cc206339e;hb=refs/heads/master

Do you know it is safe to ignore this float/double distinction in C?


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?61968>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]