Debian Codegraph @

texk/dvipdfm-x/numbers.h

raw
1 /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
2
3 Copyright (C) 2002-2020 by Jin-Hwan Cho and Shunsaku Hirata,
4 the dvipdfmx project team.
5
6 Copyright (C) 1998, 1999 by Mark A. Wicks <[email protected]>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 */
22
23 #ifndef _NUMBERS_H_
24 #define _NUMBERS_H_
25
26 #include <stdio.h>
27 #include <math.h>
28 #ifdef HAVE_INTTYPES_H
29 # include <inttypes.h>
30 #endif
31 #ifdef HAVE_STDINT_H
32 # include <stdint.h>
33 #endif
34
35 #ifndef PRId64
36 # ifdef _WIN32
37 # define PRId64 "I64d"
38 # elif SIZEOF_LONG == 8
39 # define PRId64 "ld"
40 # else
41 # define PRId64 "lld"
42 # endif
43 #endif
44
45 /* When reading numbers from binary files 1, 2, or 3 bytes are
46 interpreted as either signed or unsigned.
47
48 Four bytes from DVI, PK, TFM, or VF files always yield a signed
49 32-bit integer (int32_t), but some of them must not be negative.
50
51 Four byte numbers from JPEG2000, OpenType, or TrueType files are
52 mostly unsigned (uint32_t) and occasionally signed (int32_t).
53 */
54
55 extern unsigned char get_unsigned_byte (FILE *);
56 extern void skip_bytes (unsigned int, FILE *);
57 extern signed char get_signed_byte (FILE *);
58 extern unsigned short get_unsigned_pair (FILE *);
59 extern unsigned short sget_unsigned_pair (unsigned char *);
60 extern signed short get_signed_pair (FILE *);
61 extern unsigned int get_unsigned_triple (FILE *);
62 extern signed int get_signed_triple (FILE *);
63 extern int32_t get_signed_quad (FILE *);
64 extern uint32_t get_unsigned_quad (FILE *);
65 extern int32_t get_unsigned_num (FILE *, unsigned char);
66 extern uint32_t get_positive_quad (FILE *, const char *, const char *);
67
68 typedef int32_t fixword;
69
70 extern int32_t sqxfw (int32_t sq, fixword fw);
71
72 #ifndef MAX
73 # define MAX(a,b) ((a)>(b)?(a):(b))
74 #endif
75 #ifndef MIN
76 # define MIN(a,b) ((a)<(b)?(a):(b))
77 #endif
78 #define ISODD(n) (((n)/2)*2!=(n))
79 #define ISEVEN(n) (((n)/2)*2==(n))
80
81 #ifndef M_PI
82 # define M_PI (4.0*atan(1.0))
83 #endif
84
85 #define ROUND(n,acc) (floor(((double)n)/(acc)+0.5)*(acc))
86
87 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
88 # define __C99__
89 #endif
90
91 #ifndef __C99__
92 # ifndef round
93 # define round(v) (floor((v) + 0.5))
94 # endif
95 # ifndef trunc
96 # define trunc(v) ((v) > 0.0 ? floor((v)) : ceil((v)))
97 # endif
98 #endif
99 #define round_at(v,acc) (round(((double)(v))/(acc))*(acc))
100
101 #endif /* _NUMBERS_H_ */