source: mainline/uspace/lib/math/generic/internal.h@ f23dbf4

Last change on this file since f23dbf4 was 274b9d99, checked in by Maurizio Lombardi <mlombard@…>, 4 years ago

libm: add the pow() function

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
2 * Copyright (c) 2015 Jiri Svoboda
3 * Copyright (c) 2014 Martin Decky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef MATH_INTERNAL_H_
31#define MATH_INTERNAL_H_
32
33#include <stdint.h>
34
35#if __BE__
36
37typedef union
38{
39 double value;
40 struct
41 {
42 uint32_t msw;
43 uint32_t lsw;
44 } parts;
45 uint64_t word;
46} ieee_double_shape_type;
47
48#endif
49
50#if __LE__
51
52typedef union
53{
54 double value;
55 struct
56 {
57 uint32_t lsw;
58 uint32_t msw;
59 } parts;
60 uint64_t word;
61} ieee_double_shape_type;
62
63#endif
64
65#define EXTRACT_WORDS(ix0,ix1,d) \
66do { \
67 ieee_double_shape_type ew_u; \
68 ew_u.value = (d); \
69 (ix0) = ew_u.parts.msw; \
70 (ix1) = ew_u.parts.lsw; \
71} while (0)
72
73/* Get the more significant 32 bit int from a double. */
74#ifndef GET_HIGH_WORD
75# define GET_HIGH_WORD(i,d) \
76do { \
77 ieee_double_shape_type gh_u; \
78 gh_u.value = (d); \
79 (i) = gh_u.parts.msw; \
80} while (0)
81#endif
82
83/* Get the less significant 32 bit int from a double. */
84#ifndef GET_LOW_WORD
85# define GET_LOW_WORD(i,d) \
86do { \
87 ieee_double_shape_type gl_u; \
88 gl_u.value = (d); \
89 (i) = gl_u.parts.lsw; \
90} while (0)
91#endif
92
93/* Get all in one, efficient on 64-bit machines. */
94#ifndef EXTRACT_WORDS64
95# define EXTRACT_WORDS64(i,d) \
96do { \
97 ieee_double_shape_type gh_u; \
98 gh_u.value = (d); \
99 (i) = gh_u.word; \
100} while (0)
101#endif
102
103/* Set a double from two 32 bit ints. */
104#ifndef INSERT_WORDS
105# define INSERT_WORDS(d,ix0,ix1) \
106do { \
107 ieee_double_shape_type iw_u; \
108 iw_u.parts.msw = (ix0); \
109 iw_u.parts.lsw = (ix1); \
110 (d) = iw_u.value; \
111} while (0)
112#endif
113
114/* Get all in one, efficient on 64-bit machines. */
115#ifndef INSERT_WORDS64
116# define INSERT_WORDS64(d,i) \
117do { \
118 ieee_double_shape_type iw_u; \
119 iw_u.word = (i); \
120 (d) = iw_u.value; \
121} while (0)
122#endif
123
124/* Set the more significant 32 bits of a double from an int. */
125#ifndef SET_HIGH_WORD
126#define SET_HIGH_WORD(d,v) \
127do { \
128 ieee_double_shape_type sh_u; \
129 sh_u.value = (d); \
130 sh_u.parts.msw = (v); \
131 (d) = sh_u.value; \
132} while (0)
133#endif
134
135/* Set the less significant 32 bits of a double from an int. */
136#ifndef SET_LOW_WORD
137# define SET_LOW_WORD(d,v) \
138do { \
139 ieee_double_shape_type sl_u; \
140 sl_u.value = (d); \
141 sl_u.parts.lsw = (v); \
142 (d) = sl_u.value; \
143} while (0)
144#endif
145
146
147float __math_base_sin_32(float);
148float __math_base_cos_32(float);
149double __math_base_sin_64(double);
150double __math_base_cos_64(double);
151
152#endif
Note: See TracBrowser for help on using the repository browser.