mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Release calc version 2.10.3t5.45
This commit is contained in:
53
custom/halflen.cal
Normal file
53
custom/halflen.cal
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted.
|
||||
*
|
||||
* LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
* EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
|
||||
* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* chongo was here /\../\ chongo@toad.com
|
||||
*/
|
||||
/*
|
||||
* halflen - determine the length of numeric value in HALFs
|
||||
*
|
||||
* This file is part of the custom sample calc files.
|
||||
*
|
||||
* NOTE: You must use a calc that was compiled with ALLOW_CUSTOM= -DCUSTOM
|
||||
* and run with a -C arg.
|
||||
*/
|
||||
define halflen(num)
|
||||
{
|
||||
local baseb = custom("sysinfo","BASEB"); /* bit len of a HALF */
|
||||
|
||||
/*
|
||||
* firewall
|
||||
*/
|
||||
if (!isnum(num)) {
|
||||
return newerror("halflen only works on numeric values");
|
||||
}
|
||||
|
||||
/*
|
||||
* determine the HALF length of a numeric value
|
||||
*/
|
||||
if (num == 0) {
|
||||
/* consider 0 to be 1 HALF long */
|
||||
return 1;
|
||||
} else if (isint(num)) {
|
||||
return (highbit(num)+baseb-1)/baseb;
|
||||
} else if (isreal(num)) {
|
||||
return halflen(num(num)) + halflen(den(num));
|
||||
} else if (isnum(num)) {
|
||||
return halflen(re(num)) + halflen(im(num));
|
||||
} else {
|
||||
return newerror("halflen only works on numeric values");
|
||||
}
|
||||
}
|
||||
|
||||
if (config("lib_debug") >= 0) {
|
||||
print "halflen(num) defined";
|
||||
}
|
Reference in New Issue
Block a user