|
1 | 1 | // Copyright (c) 2014 Johannes Huning <mail@johanneshuning.com> |
2 | 2 | // Copyright (c) 2015 Christian Lundgren, Chris de Vries, and Jon Elverkilde |
3 | 3 | // |
4 | | -// This program is free software: you can redistribute it and/or modify |
5 | | -// it under the terms of the GNU Lesser General Public License as published by |
6 | | -// the Free Software Foundation, either version 3 of the License, or |
7 | | -// (at your option) any later version. |
| 4 | +// Permission is hereby granted, free of charge, to any person |
| 5 | +// obtaining a copy of this software and associated documentation |
| 6 | +// files (the "Software"), to deal in the Software without |
| 7 | +// restriction, including without limitation the rights to use, copy, |
| 8 | +// modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 | +// of the Software, and to permit persons to whom the Software is |
| 10 | +// furnished to do so, subject to the following conditions: |
8 | 11 | // |
9 | | -// This program is distributed in the hope that it will be useful, |
10 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | -// GNU Lesser General Public License for more details. |
| 12 | +// The above copyright notice and this permission notice shall be |
| 13 | +// included in all copies or substantial portions of the Software. |
| 14 | +// |
| 15 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 | +// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 | +// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +// SOFTWARE. |
13 | 23 | // |
14 | | -// You should have received a copy of the GNU Lesser General Public License |
15 | | -// along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | | - |
17 | 24 | // Format this file with |
18 | 25 | // indent -kr -i8 -sob c_src/hyper_carray.c |
19 | 26 | // before committing. |
20 | 27 |
|
21 | 28 | #include <stdint.h> |
22 | 29 | #include <stdio.h> |
23 | 30 | #include <string.h> |
24 | | -#include <tgmath.h> |
25 | 31 |
|
26 | 32 | #include "erl_nif.h" |
27 | 33 |
|
@@ -68,7 +74,7 @@ typedef struct hyper_carray *restrict carray_ptr; |
68 | 74 | */ |
69 | 75 | static void carray_alloc(unsigned int precision, carray_ptr * arr) |
70 | 76 | { |
71 | | - unsigned int nitems = pow(2, precision); |
| 77 | + unsigned int nitems = 0x01 << precision; |
72 | 78 | size_t header_size = HYPER_CARRAY_SIZE; |
73 | 79 | size_t res_size = header_size + nitems; |
74 | 80 |
|
@@ -223,7 +229,7 @@ static ERL_NIF_TERM register_sum(ErlNifEnv * env, int argc, |
223 | 229 |
|
224 | 230 | for (int i = 0; i < size; ++i) { |
225 | 231 | currval = arr->items[i]; |
226 | | - sum += pow(2, -currval); |
| 232 | + sum += 1.0 / (double) (0x01 << currval); |
227 | 233 | } |
228 | 234 |
|
229 | 235 | return enif_make_double(env, sum); |
|
0 commit comments