mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
139 lines
2.6 KiB
Plaintext
139 lines
2.6 KiB
Plaintext
/*
|
|
* deg - calculate in degrees, minutes, and seconds
|
|
*
|
|
* Copyright (C) 1999 David I. Bell
|
|
*
|
|
* Calc is open software; you can redistribute it and/or modify it under
|
|
* the terms of the version 2.1 of the GNU Lesser General Public License
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* Calc is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
|
|
* Public License for more details.
|
|
*
|
|
* A copy of version 2.1 of the GNU Lesser General Public License is
|
|
* distributed with calc under the filename COPYING-LGPL. You should have
|
|
* received a copy with calc; if not, write to Free Software Foundation, Inc.
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
|
*
|
|
* @(#) $Revision: 29.2 $
|
|
* @(#) $Id: deg.cal,v 29.2 2000/06/07 14:02:25 chongo Exp $
|
|
* @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/deg.cal,v $
|
|
*
|
|
* Under source code control: 1990/02/15 01:50:33
|
|
* File existed as early as: before 1990
|
|
*
|
|
* Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
|
|
*/
|
|
|
|
|
|
obj dms {deg, min, sec};
|
|
|
|
define dms(deg, min, sec)
|
|
{
|
|
local ans;
|
|
|
|
if (isnull(sec))
|
|
sec = 0;
|
|
if (isnull(min))
|
|
min = 0;
|
|
obj dms ans;
|
|
ans.deg = deg;
|
|
ans.min = min;
|
|
ans.sec = sec;
|
|
fixdms(&ans);
|
|
return ans;
|
|
}
|
|
|
|
|
|
define dms_add(a, b)
|
|
{
|
|
local obj dms ans;
|
|
|
|
ans.deg = 0;
|
|
ans.min = 0;
|
|
ans.sec = 0;
|
|
if (istype(a, ans)) {
|
|
ans.deg += a.deg;
|
|
ans.min += a.min;
|
|
ans.sec += a.sec;
|
|
} else
|
|
ans.deg += a;
|
|
if (istype(b, ans)) {
|
|
ans.deg += b.deg;
|
|
ans.min += b.min;
|
|
ans.sec += b.sec;
|
|
} else
|
|
ans.deg += b;
|
|
fixdms(&ans);
|
|
return ans;
|
|
}
|
|
|
|
|
|
define dms_neg(a)
|
|
{
|
|
local obj dms ans;
|
|
|
|
ans.deg = -ans.deg;
|
|
ans.min = -ans.min;
|
|
ans.sec = -ans.sec;
|
|
return ans;
|
|
}
|
|
|
|
|
|
define dms_sub(a, b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
|
|
define dms_mul(a, b)
|
|
{
|
|
local obj dms ans;
|
|
|
|
if (istype(a, ans) && istype(b, ans))
|
|
quit "Cannot multiply degrees together";
|
|
if (istype(a, ans)) {
|
|
ans.deg = a.deg * b;
|
|
ans.min = a.min * b;
|
|
ans.sec = a.sec * b;
|
|
} else {
|
|
ans.deg = b.deg * a;
|
|
ans.min = b.min * a;
|
|
ans.sec = b.sec * a;
|
|
}
|
|
fixdms(&ans);
|
|
return ans;
|
|
}
|
|
|
|
|
|
define dms_print(a)
|
|
{
|
|
print a.deg : 'd' : a.min : 'm' : a.sec : 's' :;
|
|
}
|
|
|
|
|
|
define dms_abs(a)
|
|
{
|
|
return a.deg + a.min / 60 + a.sec / 3600;
|
|
}
|
|
|
|
|
|
define fixdms(a)
|
|
{
|
|
a.min += frac(a.deg) * 60;
|
|
a.deg = int(a.deg);
|
|
a.sec += frac(a.min) * 60;
|
|
a.min = int(a.min);
|
|
a.min += a.sec // 60;
|
|
a.sec %= 60;
|
|
a.deg += a.min // 60;
|
|
a.min %= 60;
|
|
a.deg %= 360;
|
|
}
|
|
|
|
if (config("resource_debug") & 3) {
|
|
print "obj dms {deg, min, sec} defined";
|
|
}
|