source: git/src/useful.h @ 1dfd718

stereo-2025
Last change on this file since 1dfd718 was 1dfd718, checked in by Olly Betts <olly@…>, 4 months ago

Eliminate BLK() and NOP macros

Each was only used three times and probably hurt code readability
as much as they help since anyone unfamiliar with the codebase
will need to go and find their definition.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/* useful.h
2 * Lots of oddments that come in handy generally
3 * Copyright (C) 1993-2003,2004,2010,2011,2014,2025 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20/* only include once */
21#ifndef USEFUL_H
22#define USEFUL_H
23
24#ifndef PACKAGE
25# error config.h must be included first in each C/C++ source file
26#endif
27
28#include <stdlib.h> /* for Borland C which #defines max() & min() there */
29#include <stdio.h>
30#include <math.h>
31
32/* In C++ code, #include<algorithm> and use std::max and std::min instead. */
33#ifndef __cplusplus
34/* Return max/min of two numbers. */
35/* May be defined already (e.g. by Borland C in stdlib.h) */
36/* NB Bad news if X or Y has side-effects... */
37# ifndef max
38#  define max(X, Y) ((X) > (Y) ? (X) : (Y))
39# endif
40# ifndef min
41#  define min(X, Y) ((X) < (Y) ? (X) : (Y))
42# endif
43#endif
44
45/* M_PI, etc may be defined in math.h */
46#ifndef M_PI
47# ifdef PI /* MSVC defines PI IIRC */
48#  define M_PI PI
49# else
50#  define M_PI 3.14159265358979323846264338327950288419716939937510582097494459
51# endif
52#endif
53#ifndef M_PI_2
54# define M_PI_2 (M_PI / 2.0)
55#endif
56#ifndef M_PI_4
57# define M_PI_4 (M_PI / 4.0)
58#endif
59
60#define MM_PER_INCH 25.4 /* exact value */
61#define METRES_PER_FOOT 0.3048 /* exact value */
62#define POINTS_PER_INCH 72.0
63#define POINTS_PER_MM (POINTS_PER_INCH / MM_PER_INCH)
64
65#define putnl() putchar('\n')    /* print a newline char */
66#define fputnl(FH) PUTC('\n', (FH)) /* print a newline char to a file */
67/* print a line followed by a newline char to a file */
68#define fputsnl(SZ, FH) do { fputs((SZ), (FH)); PUTC('\n', (FH)); } while (0)
69#define sqrd(X) ((X) * (X))        /* macro to square things */
70
71/* 2D Euclidean distance */
72#ifndef HAVE_HYPOT
73# define hypot(X, Y) sqrt(sqrd((double)(X)) + sqrd((double)(Y)))
74#endif
75#define rad(X) ((M_PI / 180.0) * (X))  /* convert from degrees to radians */
76#define deg(X) ((180.0 / M_PI) * (X))  /* convert from radians to degrees */
77
78/* macro to convert argument to a string literal */
79#define STRING(X) STRING_(X)
80#define STRING_(X) #X
81
82#endif /* !USEFUL_H */
Note: See TracBrowser for help on using the repository browser.