<commit_before>// posit8.c: example test of the posit API for C programs using 8-bit posits
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

#define POSIT_NO_GENERICS // MSVC doesn't support _Generic so we'll leave it out from these tests
#include <posit_c_api.h>
#include <math.h> // sqrt()

int main(int argc, char* argv[])
{
	posit8_t pa, pb, pc;
	char str[posit8_str_SIZE];
	bool failures = false;

	// special case values
	pa = NAR8;
	pb = ZERO8;
	pc = posit8_addp8(pa, pb);
	posit8_str(str, pc);
	printf("posit value = %s\n", str);
	printf("posit value = 8.0x%02xp\n", posit8_bits(pc));

	pa = NAR8;
	pb = ZERO8;
	pc = posit8_subp8(pa, pb);
	posit8_str(str, pc);
	printf("posit value = %s\n", str);
	printf("posit value = 8.0x%02xp\n", posit8_bits(pc));

	pa = NAR8;
	pb = ZERO8;
	pc = posit8_mulp8(pa, pb);
	posit8_str(str, pc);
	printf("posit value = %s\n", str);
	printf("posit value = 8.0x%02xp\n", posit8_bits(pc));

	pa = NAR8;
	pb = ZERO8;
	pc = posit8_divp8(pa, pb);
	posit8_str(str, pc);
	printf("posit value = %s\n", str);
	printf("posit value = 8.0x%02xp\n", posit8_bits(pc));

	// full state space
	int fails = 0;
	for (int a = 0; a < 256; ++a) {
		printf("%d\n", a);
		pa = posit8_reinterpret(a);
		for (int b = 0; b < 256; ++b) {
			printf("%d %d\n", a, b);
			pb = posit8_reinterpret(b);
			pc = posit8_add(pa, pb);
			float da, db, dref;
			da = posit8_tof(pa);
			db = posit8_tof(pb);
			dref = da + db;
			posit8_t pref = posit8_fromf(dref);
			printf("%d %d\n", a, b);
			if (posit8_cmpp8(pref, pc)) {
				printf("FAIL: 8.0x%02xp + 8.0x%02xp produced 8.0x%02xp instead of 8.0x%02xp\n",
                    posit8_bits(pa), posit8_bits(pb), posit8_bits(pc), posit8_bits(pref));
				++fails;<commit_msg>quick cleanup of the pure and shimmed test bench for posit8_t<commit_after>// posit8.c: example test of the posit API for C programs using 8-bit posits
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

#define POSIT_NO_GENERICS // MSVC doesn't support _Generic so we'll leave it out from these tests
#include <posit_c_api.h>
#include <math.h> // sqrt()

int main(int argc, char* argv[])
{
	posit8_t pa, pb, pc;
	char str[posit8_str_SIZE];
	bool failures = false;

	// special case values
	pa = NAR8;
	pb = ZERO8;
	pc = posit8_addp8(pa, pb);
	posit8_str(str, pc);
	printf("NAR8 + 0 = %s (8.0x%02xp)\n", str, posit8_bits(pc));

	pa = NAR8;
	pb = ZERO8;
	pc = posit8_subp8(pa, pb);
	posit8_str(str, pc);
	printf("NAR8 + 0 = %s (8.0x%02xp)\n", str, posit8_bits(pc));

	pa = NAR8;
	pb = ZERO8;
	pc = posit8_mulp8(pa, pb);
	posit8_str(str, pc);
	printf("NAR8 + 0 = %s (8.0x%02xp)\n", str, posit8_bits(pc));

	pa = NAR8;
	pb = ZERO8;
	pc = posit8_divp8(pa, pb);
	posit8_str(str, pc);
	printf("NAR8 + 0 = %s (8.0x%02xp)\n", str, posit8_bits(pc));

	// full state space
	int fails = 0;
	for (int a = 0; a < 256; ++a) {
		pa = posit8_reinterpret(a);
		for (int b = 0; b < 256; ++b) {
			pb = posit8_reinterpret(b);
			pc = posit8_add(pa, pb);
			float da, db, dref;
			da = posit8_tof(pa);
			db = posit8_tof(pb);
			dref = da + db;
			posit8_t pref = posit8_fromf(dref);
			if (posit8_cmpp8(pref, pc)) {
				printf("FAIL: 8.0x%02xp + 8.0x%02xp produced 8.0x%02xp instead of 8.0x%02xp\n",
                    posit8_bits(pa), posit8_bits(pb), posit8_bits(pc), posit8_bits(pref));
				++fails;
{'fraction_non_alphanumeric': 0.16258790436005627, 'fraction_numerical': 0.053164556962025315, 'mean_word_length': 3.570694087403599, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5500366', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1532, 'n_words': 409}