/* int MagnitudeOfDecimal(pSrc); * ARGUMENT * DEC *pSrc; * * DESCRIPTION * returns the 'order of magnitude' of pSrc -- the exponent of the * largest power of 10 less than or equal to absolute value of pSrc. * Examples: MagnitudeOfDecimal(20) = 1 * MagnitudeOfDecimal(200)=2 * MagnitudeOfDecimal(2)=0 * MagnitudeOfDecimal(-.2) = -1 * MagnitudeOfDecimal(1)=0 * MagnitudeOfDecimal(3.14)=0 * MagnitudeOfDecimal(.003)= -3 * MagnitudeOfDecimal(0) = -32767 * * SIDE EFFECTS * None. * * RETURNS * The magnitude of pSrc. * * POSSIBLE ERROR CODES * * GM_NULLPOINTER * * AUTHOR * Jared Levy 5 / 18 / 1987 * Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved. * * MODIFICATIONS * */ #include #include "gm.h" #include "gmsystem.h" int MagnitudeOfDecimal(pSrc) DEC *pSrc; { SHORT p; _MacStart(GM_DMAG); _MacInVarI(pSrc); if (_MacIsDecZ(pSrc)) _MacRet( -32767); /* finds pSrc->dc.sl in wrgGMPowersOfTen80Bit[] using a linear search */ /* of 80-bit unsigned values */ p = 1; while ((p<=24) && (_CompareUnsArr(pSrc->dc.sl, &wrgGMPowersOfTen80Bit[5*p], 5) != -1)) p++; _MacRet(p - 1 - pSrc->dc.id); }