-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
build-aarch64-w64-mingw32/ | ||
.vscode/ | ||
build-*/ | ||
code/ | ||
downloads/ | ||
*.exe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,49 @@ | ||
#include <assert.h> | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
_Float128 foo (_Float128 x) | ||
// Source: https://cpufun.substack.com/p/portable-support-for-128b-floats | ||
#define M_E_LD 2.718281828459045235360287471352662498L | ||
|
||
#define assert_sizeof(type, size) \ | ||
printf ("expected: sizeof(%s) == %d\n", #type, size); \ | ||
printf ("actual: sizeof(%s) == %d\n", #type, sizeof (type)); \ | ||
assert (sizeof (type) == size); | ||
|
||
void assert_snprintf(const char* expected, const char* format, ...) | ||
{ | ||
_Complex _Float128 z1, z2; | ||
va_list list; | ||
va_start (list, format); | ||
|
||
z1 = x; | ||
z2 = x / 7.F128; | ||
z2 /= z1; | ||
const int SIZE = 1024; | ||
char actual[SIZE]; | ||
snprintf (actual, SIZE, format, list); | ||
printf ("expected: %s\n", expected); | ||
printf ("actual: %s\n", actual); | ||
assert (strncmp (expected, actual, SIZE) == 0); | ||
|
||
return (_Float128) z2; | ||
va_end(list); | ||
} | ||
|
||
_Float128 bar (_Float128 x) | ||
int main() | ||
{ | ||
return x * __builtin_huge_valf128 (); | ||
} | ||
assert_sizeof (float, 4); | ||
assert_sizeof (double, 8); | ||
assert_sizeof (long double, 8); | ||
|
||
_Float128 baz (_Float128 x) | ||
{ | ||
return x * __builtin_huge_valf128 (); | ||
} | ||
float f = 1.23456f; | ||
double d = 1.23456; | ||
long double ld = M_E_LD; | ||
|
||
assert_snprintf ("float %g => 1.23456", "float %%g => %g", f); | ||
assert_snprintf ("double %g => 1.23456", "double %%g => %g", d); | ||
assert_snprintf ("long double %g => 2.71828", "long double %%g => %g", ld); | ||
assert_snprintf ("long double %Lg => 2.71828", "long double %%Lg => %Lg", ld); | ||
assert_snprintf ("long double %qg => 2.71828", "long double %%qg => %qg", ld); | ||
assert_snprintf ("long double %Qg => 2.71828", "long double %%Qg => %Qg", ld); | ||
|
||
int main() | ||
{ | ||
foo (1.2Q); | ||
bar (1.2Q); | ||
foo (1.2F128); | ||
bar (1.2F128); | ||
baz (1.2F128); | ||
foo (1.2Q); | ||
bar (1.2Q); | ||
baz (1.2Q); | ||
|
||
printf("ok\n"); | ||
return 0; | ||
} | ||
printf ("ok\n"); | ||
|
||
return 0; | ||
} |