From a04c15fbd508bacefc40d0d670556c558870fb76 Mon Sep 17 00:00:00 2001 From: Jean-Denis Vauguet Date: Tue, 9 Jun 2009 19:27:31 +0200 Subject: [PATCH] yeah --- .../MATLAB/vectorial/3D/mantexpnt.m | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 docs/fac/stage/IPGP Saint Maur/MATLAB/vectorial/3D/mantexpnt.m diff --git a/docs/fac/stage/IPGP Saint Maur/MATLAB/vectorial/3D/mantexpnt.m b/docs/fac/stage/IPGP Saint Maur/MATLAB/vectorial/3D/mantexpnt.m new file mode 100644 index 0000000..9115b4e --- /dev/null +++ b/docs/fac/stage/IPGP Saint Maur/MATLAB/vectorial/3D/mantexpnt.m @@ -0,0 +1,37 @@ +function [expnt, mant] = mantexpnt(arg) +% returns exponant and mantisse +% TODO handle > 1D! + +if size(arg,1) == 1 && size(arg,2) == 1 + % scalar + % nothing to do yet but may be useful someday +elseif size(arg,1) == 1 || size(arg,2) == 1 + % row + % looking for the max, whatever the sign + tmin = mantexpnt(min(arg)); + tmax = mantexpnt(max(arg)); + if abs(tmin) > tmax + arg = min(arg); + else + arg = max(arg); + end +else + error('does not handle matrix or multidimensionnal arrays yet!'); +end + +sgn = sign(arg); +expnt = fix(log10(abs(arg))); +mant = sgn * 10^(log10(abs(arg))-expnt); + +if abs(mant) < 1 + mant = mant * 10; + expnt = expnt - 1; +end + +% if expnt is actually 0 +if expnt == -Inf || expnt == Inf + expnt = 0; +end + +return + -- 2.11.4.GIT