1 #include <glib.h>
2 #include <math.h>
4 /** Returns \a x wrapped around to between 0 and less than 360,
5 or 0 if \a x isn't finite.
6 **/
7 double mod360(double const x)
8 {
9 double const m = fmod(x, 360.0);
10 double const ret = ( isnan(m)
11 ? 0.0
12 : ( m < 0
13 ? m + 360
14 : m ) );
15 g_return_val_if_fail(0.0 <= ret && ret < 360.0,
16 0.0);
17 return ret;
18 }
20 /** Returns \a x wrapped around to between -180 and less than 180,
21 or 0 if \a x isn't finite.
22 **/
23 double mod360symm(double const x)
24 {
25 double m = mod360(x);
27 return m < 180.0 ? m : m - 360.0;
28 }
30 /*
31 Local Variables:
32 mode:c++
33 c-file-style:"stroustrup"
34 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
35 indent-tabs-mode:nil
36 fill-column:99
37 End:
38 */
39 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :