Skip to content

Commit

Permalink
Provide a fallback for M_PI and M_PI_2 (#412)
Browse files Browse the repository at this point in the history
As C standards does not define M_PI_2 provide a fallback and
factor out common definitions to math_utils.h
  • Loading branch information
dl1jbe authored Oct 26, 2023
1 parent dfbbf60 commit 563f35b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ noinst_HEADERS = \
keyer.h keystroke_names.h \
lancode.h last10.h listmessages.h log_utils.h \
log_to_disk.h logit.h logview.h \
makelogline.h messagechange.h muf.h \
makelogline.h math_utils.h messagechange.h muf.h \
nicebox.h note.h netkeyer.h\
paccdx.h parse_logcfg.h printcall.h \
paccdx.h parse_logcfg.h plugin.h printcall.h \
Expand Down
37 changes: 37 additions & 0 deletions src/math_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Tlf - contest logging program for amateur radio operators
* Copyright (C) 2023 Thomas Beierlein <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/


#ifndef MATH_UTILS_H
#define MATH_UTILS_H

/* Make sure math.h is included before the following definitions */
#ifndef MATH_H
#include <math.h>
#endif

/* provide a fallback for M_PI_2 as C standard does not guarantee the definition
of these constant */
#ifndef M_PI_2
# define M_PI_2 1.57079632679489661923 /* pi/2 */
#endif

#define RADIAN (90.0 / M_PI_2)

#endif
3 changes: 1 addition & 2 deletions src/muf.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include "get_time.h"
#include "globalvars.h"
#include "getwwv.h"
#include "math_utils.h"
#include "sunup.h"
#include "qrb.h"
#include "tlf_panel.h"
#include "ui_utils.h"


// message splitters:
// line[0] - original line, content can be modified in-place
// line[1],line[2] - pointers to subsequent lines within line[0], initially NULL
Expand Down Expand Up @@ -183,7 +183,6 @@ September 26, 1986.
*********************************************************************/

#define ARC_IN_KM 111.2 // same as in Hamlib's locator.c
#define RADIAN (180.0 / M_PI)

int month;

Expand Down
4 changes: 1 addition & 3 deletions src/sunup.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include <time.h>

#include "get_time.h"

#define RADIAN (180.0 / M_PI)

#include "math_utils.h"

/** Compute sun up and down at given latitude
*
Expand Down

0 comments on commit 563f35b

Please sign in to comment.