File: d2dms

package info (click to toggle)
calc 2.15.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,848 kB
  • sloc: ansic: 62,147; makefile: 7,664; sh: 503; awk: 74; sed: 7
file content (130 lines) | stat: -rw-r--r-- 4,443 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
NAME
    d2dms - convert degrees into degrees, minutes, and seconds

SYNOPSIS
    d2dms(degs, d, m, s [,rnd])

TYPES
    degs        real
    d           null-or-real-valued lvalue with assign-to permission
    m           null-or-real-valued lvalue with assign-to permission
    s           null-or-real-valued lvalue with assign-to permission
    rnd         nonnegative integer, defaults to config("mod")

    return      mod(degs, 360, rnd)

DESCRIPTION
    Convert degs degrees into d degrees, m minutes, and s seconds.

    The return value is a normalized number of degrees, and is equivalent
    to the following:

        return_value = mod(degs, 360, rnd);

    The argument rnd, if not given, defaults to config("mod").
    For more information on the effects of rnd, see "help mod".

    Depending on the rounding mode, the return could be a real value
    in the interval [0, 360) or a real value in the interval (-360, 0].
    For the default round mode, the return value is in the interval [0, 360).

    The d argument will be an integer number of degrees.

    The value d will be set as if the following were used:

        d = int(return_value);

    For some rounding modes, d will be an integer in the interval [0, 360).
    For other rounding modes, d will be an integer in the interval (-360, 0].
    For the default round mode, d is in the interval [0, 360).

    The m argument will be an integer number of minutes.

    The value m will be set as if the following were used:

        tmp = return_value - d;
        tmp_m = tmp * 60;
        free(tmp);
        m = int(tmp_m);

    For some rounding modes, m will be an integer in the interval [0, 60).
    For other rounding modes, m will be an integer in the interval (-60, 0].
    For the default round mode, m will be in the interval [0, 60).

    The s argument will be a real number of seconds.

    The value s will be set as if the following were used:

        tmp = tmp_m - m;
        free(tmp_m);
        s = tmp * 60;
        free(tmp);

    For some rounding modes, s will be a real value in the interval [0, 60).
    For other rounding modes, s will be a real value in the interval (-60, 0].
    For the default round mode, s will be in the interval [0, 60).

    The following shows relationship between the return value and the resulting
    d, m, and s values:

        return_value == d + m/60 + s/3600;

EXAMPLE
    ; ## if args are undefined, pre-declare them or assign them as args

    ; global d, m, s;

    ; print d2dms(12.3456,d,m,s), d, m, s;
    12.3456 12 20 44.16
    ; print d2dms(1234.5678,d,m,s), d, m, s;
    154.5678 154 34 4.08
    ; print d2dms(-1234.5678,d,m,s), d, m, s;
    205.4322 205 25 55.92

    ; print d2dms(654.321,deg=,min=,sec=), deg, min, sec;
    294.321, 294, 19, 15.6
    ; print d2dms(-654.321,deg=,min=,sec=), deg, min, sec;
    65.679 65 40 44.4
    ; print d2dms(360.321,deg=,min=,sec=), deg, min, sec;
    0.321 0 19 15.6

    ; ## certain non-default rounding modes can return negative values

    ; print d2dms(654.321,deg=,min=,sec=,1), deg, min, sec;
    -65.679 -65 -40 -44.4
    ; print d2dms(-654.321,deg=,min=,sec=,1), deg, min, sec;
    -294.321 -294 -19 -15.6
    ; print d2dms(360.321,deg=,min=,sec=,1), deg, min, sec;
    -359.679 -359 -40 -44.4

LIMITS
    none

LINK LIBRARY
    none

SEE ALSO
    config, d2dm, dm2d, dms2d, g2gm, g2gms, gm2g, gms2g,
    h2hm, h2hms, hm2d, hms2d, mod

## Copyright (C) 2021  Landon Curt Noll
##
## 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.
## 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
##
## Under source code control:   2021/09/25 17:24:51
## File existed as early as:    2021
##
## chongo <was here> /\oo/\     http://www.isthe.com/chongo/
## Share and enjoy!  :-)        http://www.isthe.com/chongo/tech/comp/calc/