| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 2 | 3 | const tests = @import("tests.zig"); |
| 3 | 4 | const nl = std.cstr.line_sep; |
| 4 | 5 | |
| ... | ... | @@ -1683,38 +1684,41 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { |
| 1683 | 1684 | // TODO: add isnan check for long double once bitfield support is added |
| 1684 | 1685 | // (needed for x86_64-windows-gnu) |
| 1685 | 1686 | // TODO: add isinf check for long double once std.math.isInf supports c_longdouble |
| 1686 | | cases.add("NAN and INFINITY", |
| 1687 | | \\#include <math.h> |
| 1688 | | \\#include <stdint.h> |
| 1689 | | \\#include <stdlib.h> |
| 1690 | | \\union uf { uint32_t u; float f; }; |
| 1691 | | \\#define CHECK_NAN(STR, VAL) { \ |
| 1692 | | \\ union uf unpack = {.f = __builtin_nanf(STR)}; \ |
| 1693 | | \\ if (!isnan(unpack.f)) abort(); \ |
| 1694 | | \\ if (unpack.u != VAL) abort(); \ |
| 1695 | | \\} |
| 1696 | | \\int main(void) { |
| 1697 | | \\ float f_nan = NAN; |
| 1698 | | \\ if (!isnan(f_nan)) abort(); |
| 1699 | | \\ double d_nan = NAN; |
| 1700 | | \\ if (!isnan(d_nan)) abort(); |
| 1701 | | \\ CHECK_NAN("0", 0x7FC00000); |
| 1702 | | \\ CHECK_NAN("", 0x7FC00000); |
| 1703 | | \\ CHECK_NAN("1", 0x7FC00001); |
| 1704 | | \\ CHECK_NAN("0x7FC00000", 0x7FC00000); |
| 1705 | | \\ CHECK_NAN("0x7FC0000F", 0x7FC0000F); |
| 1706 | | \\ CHECK_NAN("0x7FC000F0", 0x7FC000F0); |
| 1707 | | \\ CHECK_NAN("0x7FC00F00", 0x7FC00F00); |
| 1708 | | \\ CHECK_NAN("0x7FC0F000", 0x7FC0F000); |
| 1709 | | \\ CHECK_NAN("0x7FCF0000", 0x7FCF0000); |
| 1710 | | \\ CHECK_NAN("0xFFFFFFFF", 0x7FFFFFFF); |
| 1711 | | \\ float f_inf = INFINITY; |
| 1712 | | \\ if (!isinf(f_inf)) abort(); |
| 1713 | | \\ double d_inf = INFINITY; |
| 1714 | | \\ if (!isinf(d_inf)) abort(); |
| 1715 | | \\ return 0; |
| 1716 | | \\} |
| 1717 | | , ""); |
| 1687 | // TODO https://github.com/ziglang/zig/issues/12630 |
| 1688 | if (!(builtin.zig_backend == .stage2_llvm and builtin.target.os.tag == .windows)) { |
| 1689 | cases.add("NAN and INFINITY", |
| 1690 | \\#include <math.h> |
| 1691 | \\#include <stdint.h> |
| 1692 | \\#include <stdlib.h> |
| 1693 | \\union uf { uint32_t u; float f; }; |
| 1694 | \\#define CHECK_NAN(STR, VAL) { \ |
| 1695 | \\ union uf unpack = {.f = __builtin_nanf(STR)}; \ |
| 1696 | \\ if (!isnan(unpack.f)) abort(); \ |
| 1697 | \\ if (unpack.u != VAL) abort(); \ |
| 1698 | \\} |
| 1699 | \\int main(void) { |
| 1700 | \\ float f_nan = NAN; |
| 1701 | \\ if (!isnan(f_nan)) abort(); |
| 1702 | \\ double d_nan = NAN; |
| 1703 | \\ if (!isnan(d_nan)) abort(); |
| 1704 | \\ CHECK_NAN("0", 0x7FC00000); |
| 1705 | \\ CHECK_NAN("", 0x7FC00000); |
| 1706 | \\ CHECK_NAN("1", 0x7FC00001); |
| 1707 | \\ CHECK_NAN("0x7FC00000", 0x7FC00000); |
| 1708 | \\ CHECK_NAN("0x7FC0000F", 0x7FC0000F); |
| 1709 | \\ CHECK_NAN("0x7FC000F0", 0x7FC000F0); |
| 1710 | \\ CHECK_NAN("0x7FC00F00", 0x7FC00F00); |
| 1711 | \\ CHECK_NAN("0x7FC0F000", 0x7FC0F000); |
| 1712 | \\ CHECK_NAN("0x7FCF0000", 0x7FCF0000); |
| 1713 | \\ CHECK_NAN("0xFFFFFFFF", 0x7FFFFFFF); |
| 1714 | \\ float f_inf = INFINITY; |
| 1715 | \\ if (!isinf(f_inf)) abort(); |
| 1716 | \\ double d_inf = INFINITY; |
| 1717 | \\ if (!isinf(d_inf)) abort(); |
| 1718 | \\ return 0; |
| 1719 | \\} |
| 1720 | , ""); |
| 1721 | } |
| 1718 | 1722 | |
| 1719 | 1723 | cases.add("signed array subscript. Issue #8556", |
| 1720 | 1724 | \\#include <stdint.h> |