OpenRadioss
2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
adler32.cpp
Go to the documentation of this file.
1
//Copyright> OpenRadioss
2
//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3
//Copyright>
4
//Copyright> This program is free software: you can redistribute it and/or modify
5
//Copyright> it under the terms of the GNU Affero General Public License as published by
6
//Copyright> the Free Software Foundation, either version 3 of the License, or
7
//Copyright> (at your option) any later version.
8
//Copyright>
9
//Copyright> This program is distributed in the hope that it will be useful,
10
//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11
//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
//Copyright> GNU Affero General Public License for more details.
13
//Copyright>
14
//Copyright> You should have received a copy of the GNU Affero General Public License
15
//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16
//Copyright>
17
//Copyright>
18
//Copyright> Commercial Alternative: Altair Radioss Software
19
//Copyright>
20
//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21
//Copyright> software under a commercial license. Contact Altair to discuss further if the
22
//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23
#include <cstddef>
24
#include <cstdint>
25
#include <limits>
26
#include <cmath>
27
#include <iostream>
28
constexpr
uint32_t
ROOT
= 65521;
29
30
extern
"C"
void
cpp_adler32
(
const
unsigned
char
* data,
int
len,
int
* result) {
31
uint32_t a = 1, b = 0;
32
for
(
size_t
i = 0; i < len; ++i) {
33
a = (a + data[i]) %
ROOT
;
34
b = (b + a) %
ROOT
;
35
}
36
// cast the result into an int (32 bits)
37
uint32_t
r
= (b << 16) | a;
38
*result = *
reinterpret_cast<
int32_t*
>
(&
r
);
39
}
40
41
42
// test cpp_adler32
43
44
void
test_cpp_adler32
()
45
{
46
double
* data =
new
double
[100];
47
double
* data2 =
new
double
[100];
48
49
for
(
int
i = 0; i < 100; ++i) {
50
data[i] = i;
51
data2[i] = i;
52
}
53
54
// find the next representable value of data2[50]
55
data2[50] = std::nextafter(data2[50], std::numeric_limits<double>::max());
56
57
int
result1, result2;
58
cpp_adler32
(
reinterpret_cast<
unsigned
char
*
>
(data), 100 *
sizeof
(
double
), &result1);
59
cpp_adler32
(
reinterpret_cast<
unsigned
char
*
>
(data2), 100 *
sizeof
(
double
), &result2);
60
//print the two values
61
std::cout <<
"result1: "
<< result1 << std::endl;
62
std::cout <<
"result2: "
<< result2 << std::endl;
63
64
}
test_cpp_adler32
void test_cpp_adler32()
Definition
adler32.cpp:44
ROOT
constexpr uint32_t ROOT
Definition
adler32.cpp:28
cpp_adler32
void cpp_adler32(const unsigned char *data, int len, int *result)
Definition
adler32.cpp:30
r
r
Definition
schur_example.m:55
engine
source
mpi
output
adler32.cpp
Generated by
1.15.0