Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 4b1abc4

Browse files
authored
Merge pull request #16 from elverkilde/fix/carray
Fix/carray - Merging the pull request from @elverkilde as the permission has been given by all three contributors @elverkilde @chrisavl and @johannesh to change license to MIT
2 parents 55b7a63 + bef80ca commit 4b1abc4

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

c_src/hyper_carray.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
// Copyright (c) 2014 Johannes Huning <mail@johanneshuning.com>
22
// Copyright (c) 2015 Christian Lundgren, Chris de Vries, and Jon Elverkilde
33
//
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:
811
//
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.
1323
//
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-
1724
// Format this file with
1825
// indent -kr -i8 -sob c_src/hyper_carray.c
1926
// before committing.
2027

2128
#include <stdint.h>
2229
#include <stdio.h>
2330
#include <string.h>
24-
#include <tgmath.h>
2531

2632
#include "erl_nif.h"
2733

@@ -68,7 +74,7 @@ typedef struct hyper_carray *restrict carray_ptr;
6874
*/
6975
static void carray_alloc(unsigned int precision, carray_ptr * arr)
7076
{
71-
unsigned int nitems = pow(2, precision);
77+
unsigned int nitems = 0x01 << precision;
7278
size_t header_size = HYPER_CARRAY_SIZE;
7379
size_t res_size = header_size + nitems;
7480

@@ -223,7 +229,7 @@ static ERL_NIF_TERM register_sum(ErlNifEnv * env, int argc,
223229

224230
for (int i = 0; i < size; ++i) {
225231
currval = arr->items[i];
226-
sum += pow(2, -currval);
232+
sum += 1.0 / (double) (0x01 << currval);
227233
}
228234

229235
return enif_make_double(env, sum);

0 commit comments

Comments
 (0)