Sun position
Sun position algorithm
instead-of-math.h File Reference

instead-of-math.h - header to be included instead of math.h More...

Go to the source code of this file.

Functions

static void sincos (double angle_rad, double *sinA, double *cosA)
 Calculates sine and cosine of an angle. More...
 
static double normalize (double x, double range)
 Normalizes a cyclic double precision floating point variable x to the interval [0, range), assuming range is > 0. More...
 

Detailed Description

instead-of-math.h - header to be included instead of math.h

Author
David Hoadley vcrum.nosp@m.ble@.nosp@m.westn.nosp@m.et.c.nosp@m.om.au

This header needs to be included instead of the standard C library header math.h, in order to provide some routines that are missing or possibly missing from math.h. This header will include math.h for you.

The reason it must be included instead of math.h is a little obscure. One of the routines we want is the sincos() routine. Two versions of math.h actually do have it: The GNU C library does, and the Apple Clang library also has it, but under a different name.

The problem is, to gain access to the function, we need to include the appropriate incantation BEFORE including math.h if we are using the GNU C library, but we need to add definitions AFTER including math.h if we are using the Apple Clang library.

So use this header instead of math.h to look after this problem.

This header also provides the following missing function:

  • normalize()
    A proper modulo function. Unlike fmod(), result is always positive. Used to to normalize a cyclic variable to a range, e.g. an angle in radian to the range [0, 2Pi), or an angle in degrees to the range [0, 360.0)

Definition in file instead-of-math.h.

Function Documentation

◆ sincos()

static void sincos ( double  angle_rad,
double *  sinA,
double *  cosA 
)
inlinestatic

Calculates sine and cosine of an angle.

Where the math library supports it, this is more efficient than calling sin() and cos() separately.

Parameters
[in]angle_radAngle whose sine and cosine is wanted (radian)
[out]sinAsine of angle angle_rad
[out]cosAcosine of angle angle_rad

Definition at line 114 of file instead-of-math.h.

◆ normalize()

static double normalize ( double  x,
double  range 
)
inlinestatic

Normalizes a cyclic double precision floating point variable x to the interval [0, range), assuming range is > 0.

(If range is negative, this will normalize x to the interval (range, 0], but this is not the main use case for this function.)

Returns
The value of x, within the range [0, range)
Parameters
[in]xThe variable (e.g. an angle in degrees or radian)
[in]rangeThe range to normalize x to (e.g. 2Pi or 360.0). It must be non-zero.

This function returns the same results as fmod() for positive x and range. Where it differs is in its handling of negative values of x.


Definition at line 144 of file instead-of-math.h.