File: CheckFloatingPointFormat.c

package info (click to toggle)
swi-prolog 8.0.2%2Bdfsg-3%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 72,036 kB
  • sloc: ansic: 349,612; perl: 306,654; java: 5,208; cpp: 4,436; sh: 3,042; ruby: 1,594; yacc: 845; makefile: 136; xml: 82; sed: 12; sql: 6
file content (24 lines) | stat: -rw-r--r-- 601 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <math.h>
#include <stdio.h>
#include <stdint.h>

int main(int argc, char* argv[]) {
	const double numbers[8] = {
		/* the IEEE-754 representation of the number below consists of the
		 * first eight letters of the uppercase alphabet. Their order will
		 * reveal the endianness we are dealing with. */
		2.39373654120722785592079162598E6, 0, 0, 0,
		/* these are just dummies */
		1234567, 2345678, 3456789, 4567890 };
	double result;
	const double *ptr = numbers, *end = numbers + 8;
	int i;

	result = 0.0;
	while (ptr < end) {
		result += *ptr;
		ptr++;
	}

	return (result == 12345.0);
}