[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
log2 replacement
From: |
Jaroslav Hajek |
Subject: |
log2 replacement |
Date: |
Fri, 25 Apr 2008 15:38:37 +0200 |
hello,
please consider the attached changeset.
The current log2 behaviour with two outputs (`[f, e] = log2(x)') is
inconsistent with Matlab in a number of cases, (x = Inf, x = NaN) or
just plain wrong (x = realmax). Also, on most of the systems the
2-output version can be mapped directly to frexp (a C89 function),
which is probably what Matlab also does. I have implemented the
single-output log2 as a mapper for octave_value (aka log, log10 etc),
and the two-output version as an overload in liboctave/lo-mappers.cc
with a replacement if frexp is not detected. The DEFUN is in
DLD-FUNCTIONS rather than mappers.cc directly, because it is not a
simple mapper and thus did not seem to fit "aesthetically" to
mappers.cc (but that can be easily changed).
Note that the 2-output version is also extended beyond matlab
behaviour for complex input - while matlab ignores the imaginary part
(with a warning), this new version gives the result with f complex,
satisfying 1/2 <= abs(f) < 1, e integer - because it makes good sense
also for complex numbers.
regards,
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
log2.diff
Description: Text Data
- log2 replacement,
Jaroslav Hajek <=