@zigc/lib 0.16.0-test.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/c/math.zig +135 -35
- package/c/stropts.zig +17 -0
- package/c.zig +1 -0
- package/compiler/aro/aro/Attribute/names.zig +604 -589
- package/compiler/aro/aro/Attribute.zig +202 -116
- package/compiler/aro/aro/Builtins/common.zig +874 -863
- package/compiler/aro/aro/Builtins/eval.zig +15 -7
- package/compiler/aro/aro/Builtins.zig +0 -1
- package/compiler/aro/aro/CodeGen.zig +3 -1
- package/compiler/aro/aro/Compilation.zig +120 -97
- package/compiler/aro/aro/Diagnostics.zig +21 -17
- package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
- package/compiler/aro/aro/Driver.zig +124 -50
- package/compiler/aro/aro/LangOpts.zig +12 -2
- package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
- package/compiler/aro/aro/Parser.zig +336 -142
- package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
- package/compiler/aro/aro/Preprocessor.zig +127 -56
- package/compiler/aro/aro/Target.zig +17 -12
- package/compiler/aro/aro/Tokenizer.zig +31 -14
- package/compiler/aro/aro/Toolchain.zig +4 -7
- package/compiler/aro/aro/Tree.zig +178 -148
- package/compiler/aro/aro/TypeStore.zig +82 -24
- package/compiler/aro/aro/Value.zig +13 -17
- package/compiler/aro/aro/features.zig +1 -0
- package/compiler/aro/aro/pragmas/once.zig +0 -1
- package/compiler/aro/aro/record_layout.zig +3 -3
- package/compiler/aro/assembly_backend/x86_64.zig +3 -4
- package/compiler/aro/backend/Assembly.zig +1 -2
- package/compiler/aro/backend/Interner.zig +2 -2
- package/compiler/aro/backend/Ir.zig +100 -92
- package/compiler/aro/include/ptrcheck.h +49 -0
- package/compiler/aro/main.zig +26 -10
- package/compiler/build_runner.zig +1 -0
- package/compiler/objdump.zig +93 -0
- package/compiler/reduce.zig +5 -1
- package/compiler/resinator/compile.zig +2 -2
- package/compiler/resinator/main.zig +7 -1
- package/compiler/resinator/preprocess.zig +1 -3
- package/compiler/std-docs.zig +8 -1
- package/compiler/test_runner.zig +193 -61
- package/compiler/translate-c/MacroTranslator.zig +80 -11
- package/compiler/translate-c/PatternList.zig +1 -9
- package/compiler/translate-c/Scope.zig +43 -6
- package/compiler/translate-c/Translator.zig +364 -126
- package/compiler/translate-c/ast.zig +19 -11
- package/compiler/translate-c/main.zig +75 -16
- package/compiler_rt/cos.zig +141 -52
- package/compiler_rt/limb64.zig +266 -0
- package/compiler_rt/long_double.zig +37 -0
- package/compiler_rt/mulo.zig +6 -1
- package/compiler_rt/rem_pio2l.zig +173 -0
- package/compiler_rt/sin.zig +140 -55
- package/compiler_rt/sincos.zig +279 -72
- package/compiler_rt/tan.zig +118 -47
- package/compiler_rt/trig.zig +256 -6
- package/compiler_rt.zig +2 -0
- package/fuzzer.zig +855 -307
- package/libc/musl/src/math/pow.c +343 -0
- package/package.json +1 -1
- package/std/Build/Fuzz.zig +6 -19
- package/std/Build/Module.zig +1 -1
- package/std/Build/Step/CheckObject.zig +3 -3
- package/std/Build/Step/Compile.zig +18 -0
- package/std/Build/Step/ConfigHeader.zig +49 -33
- package/std/Build/Step/InstallArtifact.zig +18 -0
- package/std/Build/Step/Run.zig +536 -87
- package/std/Build/Step/TranslateC.zig +0 -6
- package/std/Build/Step.zig +8 -15
- package/std/Build/WebServer.zig +29 -17
- package/std/Build/abi.zig +47 -11
- package/std/Build.zig +17 -14
- package/std/Io/Dispatch.zig +2 -0
- package/std/Io/File/Reader.zig +3 -1
- package/std/Io/File.zig +1 -0
- package/std/Io/Kqueue.zig +2 -2
- package/std/Io/Threaded.zig +181 -143
- package/std/Io/Uring.zig +2 -1
- package/std/Io.zig +970 -2
- package/std/Target.zig +3 -2
- package/std/Thread.zig +8 -3
- package/std/array_hash_map.zig +96 -555
- package/std/array_list.zig +22 -31
- package/std/bit_set.zig +22 -6
- package/std/builtin/assembly.zig +68 -0
- package/std/c.zig +17 -17
- package/std/compress/flate/Compress.zig +3 -3
- package/std/crypto/Certificate/Bundle.zig +15 -1
- package/std/crypto/codecs/asn1.zig +33 -18
- package/std/crypto/codecs/base64_hex_ct.zig +14 -4
- package/std/debug/Dwarf.zig +29 -9
- package/std/debug/Info.zig +4 -0
- package/std/debug/MachOFile.zig +46 -8
- package/std/debug/Pdb.zig +539 -36
- package/std/debug/SelfInfo/Elf.zig +19 -18
- package/std/debug/SelfInfo/MachO.zig +18 -7
- package/std/debug/SelfInfo/Windows.zig +138 -36
- package/std/debug.zig +179 -65
- package/std/enums.zig +25 -19
- package/std/heap/ArenaAllocator.zig +145 -154
- package/std/heap/debug_allocator.zig +7 -7
- package/std/http/Client.zig +10 -6
- package/std/http.zig +11 -9
- package/std/json/Stringify.zig +3 -3
- package/std/json/dynamic.zig +4 -4
- package/std/math/big/int.zig +16 -17
- package/std/mem/Allocator.zig +4 -5
- package/std/mem.zig +48 -0
- package/std/os/emscripten.zig +1 -17
- package/std/os/linux.zig +7 -2
- package/std/os/windows.zig +2 -2
- package/std/pdb.zig +143 -4
- package/std/posix.zig +6 -12
- package/std/priority_dequeue.zig +13 -12
- package/std/priority_queue.zig +5 -4
- package/std/process/Child.zig +1 -1
- package/std/process/Environ.zig +1 -1
- package/std/start.zig +17 -4
- package/std/std.zig +19 -6
- package/std/testing/FailingAllocator.zig +4 -4
- package/std/testing/Smith.zig +37 -2
- package/std/zig/Ast/Render.zig +186 -458
- package/std/zig/Ast.zig +0 -4
- package/std/zig/AstGen.zig +44 -7
- package/std/zig/AstSmith.zig +2602 -0
- package/std/zig/Client.zig +8 -3
- package/std/zig/Parse.zig +83 -74
- package/std/zig/Server.zig +26 -0
- package/std/zig/Zir.zig +17 -0
- package/std/zig/c_translation/helpers.zig +14 -9
- package/std/zig/llvm/Builder.zig +107 -48
- package/std/zig/system.zig +20 -4
- package/std/zig/tokenizer.zig +2 -1
- package/std/zig.zig +6 -0
- package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
- package/libc/mingw/complex/cabs.c +0 -48
- package/libc/mingw/complex/cabsf.c +0 -48
- package/libc/mingw/complex/cacos.c +0 -50
- package/libc/mingw/complex/cacosf.c +0 -50
- package/libc/mingw/complex/carg.c +0 -48
- package/libc/mingw/complex/cargf.c +0 -48
- package/libc/mingw/complex/casin.c +0 -50
- package/libc/mingw/complex/casinf.c +0 -50
- package/libc/mingw/complex/catan.c +0 -50
- package/libc/mingw/complex/catanf.c +0 -50
- package/libc/mingw/complex/ccos.c +0 -50
- package/libc/mingw/complex/ccosf.c +0 -50
- package/libc/mingw/complex/cexp.c +0 -48
- package/libc/mingw/complex/cexpf.c +0 -48
- package/libc/mingw/complex/cimag.c +0 -48
- package/libc/mingw/complex/cimagf.c +0 -48
- package/libc/mingw/complex/clog.c +0 -48
- package/libc/mingw/complex/clog10.c +0 -49
- package/libc/mingw/complex/clog10f.c +0 -49
- package/libc/mingw/complex/clogf.c +0 -48
- package/libc/mingw/complex/conj.c +0 -48
- package/libc/mingw/complex/conjf.c +0 -48
- package/libc/mingw/complex/cpow.c +0 -48
- package/libc/mingw/complex/cpowf.c +0 -48
- package/libc/mingw/complex/cproj.c +0 -48
- package/libc/mingw/complex/cprojf.c +0 -48
- package/libc/mingw/complex/creal.c +0 -48
- package/libc/mingw/complex/crealf.c +0 -48
- package/libc/mingw/complex/csin.c +0 -50
- package/libc/mingw/complex/csinf.c +0 -50
- package/libc/mingw/complex/csqrt.c +0 -48
- package/libc/mingw/complex/csqrtf.c +0 -48
- package/libc/mingw/complex/ctan.c +0 -50
- package/libc/mingw/complex/ctanf.c +0 -50
- package/libc/mingw/math/arm/s_rint.c +0 -86
- package/libc/mingw/math/arm/s_rintf.c +0 -51
- package/libc/mingw/math/arm/sincos.S +0 -30
- package/libc/mingw/math/arm-common/sincosl.c +0 -13
- package/libc/mingw/math/arm64/rint.c +0 -12
- package/libc/mingw/math/arm64/rintf.c +0 -12
- package/libc/mingw/math/arm64/sincos.S +0 -32
- package/libc/mingw/math/bsd_private_base.h +0 -148
- package/libc/mingw/math/frexpf.c +0 -13
- package/libc/mingw/math/frexpl.c +0 -71
- package/libc/mingw/math/x86/acosf.c +0 -29
- package/libc/mingw/math/x86/atanf.c +0 -23
- package/libc/mingw/math/x86/atanl.c +0 -18
- package/libc/mingw/math/x86/cos.def.h +0 -65
- package/libc/mingw/math/x86/cosl.c +0 -46
- package/libc/mingw/math/x86/cosl_internal.S +0 -55
- package/libc/mingw/math/x86/ldexp.c +0 -23
- package/libc/mingw/math/x86/scalbn.S +0 -41
- package/libc/mingw/math/x86/scalbnf.S +0 -40
- package/libc/mingw/math/x86/sin.def.h +0 -65
- package/libc/mingw/math/x86/sinl.c +0 -46
- package/libc/mingw/math/x86/sinl_internal.S +0 -58
- package/libc/mingw/math/x86/tanl.S +0 -62
- package/libc/mingw/misc/btowc.c +0 -28
- package/libc/mingw/misc/wcstof.c +0 -66
- package/libc/mingw/misc/wcstoimax.c +0 -132
- package/libc/mingw/misc/wcstoumax.c +0 -126
- package/libc/mingw/misc/wctob.c +0 -29
- package/libc/mingw/misc/winbs_uint64.c +0 -6
- package/libc/mingw/misc/winbs_ulong.c +0 -6
- package/libc/mingw/misc/winbs_ushort.c +0 -6
- package/libc/mingw/stdio/_Exit.c +0 -10
- package/libc/mingw/stdio/_findfirst64i32.c +0 -21
- package/libc/mingw/stdio/_findnext64i32.c +0 -21
- package/libc/mingw/stdio/_fstat64i32.c +0 -37
- package/libc/mingw/stdio/_stat64i32.c +0 -37
- package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
- package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
- package/libc/mingw/stdio/_wstat64i32.c +0 -37
- package/libc/musl/src/legacy/isastream.c +0 -7
- package/libc/musl/src/legacy/valloc.c +0 -8
- package/libc/musl/src/math/__cosl.c +0 -96
- package/libc/musl/src/math/__sinl.c +0 -78
- package/libc/musl/src/math/__tanl.c +0 -143
- package/libc/musl/src/math/aarch64/lrint.c +0 -10
- package/libc/musl/src/math/aarch64/lrintf.c +0 -10
- package/libc/musl/src/math/aarch64/rintf.c +0 -7
- package/libc/musl/src/math/cosl.c +0 -39
- package/libc/musl/src/math/fdim.c +0 -10
- package/libc/musl/src/math/finite.c +0 -7
- package/libc/musl/src/math/finitef.c +0 -7
- package/libc/musl/src/math/frexp.c +0 -23
- package/libc/musl/src/math/frexpf.c +0 -23
- package/libc/musl/src/math/frexpl.c +0 -29
- package/libc/musl/src/math/i386/lrint.c +0 -8
- package/libc/musl/src/math/i386/lrintf.c +0 -8
- package/libc/musl/src/math/i386/rintf.c +0 -7
- package/libc/musl/src/math/lrint.c +0 -72
- package/libc/musl/src/math/lrintf.c +0 -8
- package/libc/musl/src/math/powerpc64/lrint.c +0 -16
- package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
- package/libc/musl/src/math/rintf.c +0 -30
- package/libc/musl/src/math/s390x/rintf.c +0 -15
- package/libc/musl/src/math/sincosl.c +0 -60
- package/libc/musl/src/math/sinl.c +0 -41
- package/libc/musl/src/math/tanl.c +0 -29
- package/libc/musl/src/math/x32/lrint.s +0 -5
- package/libc/musl/src/math/x32/lrintf.s +0 -5
- package/libc/musl/src/math/x86_64/lrint.c +0 -8
- package/libc/musl/src/math/x86_64/lrintf.c +0 -8
- package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Nurul Huda (Apon).
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/c/math.zig
CHANGED
|
@@ -35,33 +35,47 @@ comptime {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
38
|
-
symbol(&
|
|
38
|
+
symbol(&frexpf, "frexpf");
|
|
39
|
+
symbol(&frexpl, "frexpl");
|
|
39
40
|
symbol(&hypotf, "hypotf");
|
|
40
41
|
symbol(&hypotl, "hypotl");
|
|
41
|
-
symbol(&modff, "modff");
|
|
42
42
|
symbol(&modfl, "modfl");
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
46
|
+
symbol(&atanl, "atanl");
|
|
47
|
+
symbol(©signl, "copysignl");
|
|
45
48
|
symbol(&nanl, "nanl");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ((builtin.target.isMinGW() and builtin.cpu.arch == .x86) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
52
|
+
symbol(&acosf, "acosf");
|
|
53
|
+
symbol(&atanf, "atanf");
|
|
54
|
+
symbol(&coshf, "coshf");
|
|
55
|
+
symbol(&modff, "modff");
|
|
46
56
|
symbol(&tanhf, "tanhf");
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
50
60
|
symbol(&acos, "acos");
|
|
51
|
-
symbol(&acosf, "acosf");
|
|
52
61
|
symbol(&acoshf, "acoshf");
|
|
53
62
|
symbol(&asin, "asin");
|
|
54
63
|
symbol(&atan, "atan");
|
|
55
|
-
symbol(&atanf, "atanf");
|
|
56
|
-
symbol(&atanl, "atanl");
|
|
57
64
|
symbol(&cbrt, "cbrt");
|
|
58
65
|
symbol(&cbrtf, "cbrtf");
|
|
59
66
|
symbol(&cosh, "cosh");
|
|
60
67
|
symbol(&exp10, "exp10");
|
|
61
68
|
symbol(&exp10f, "exp10f");
|
|
69
|
+
symbol(&fdim, "fdim");
|
|
70
|
+
symbol(&finite, "finite");
|
|
71
|
+
symbol(&finitef, "finitef");
|
|
72
|
+
symbol(&frexp, "frexp");
|
|
62
73
|
symbol(&hypot, "hypot");
|
|
74
|
+
symbol(&lrint, "lrint");
|
|
75
|
+
symbol(&lrintf, "lrintf");
|
|
63
76
|
symbol(&modf, "modf");
|
|
64
|
-
symbol(&
|
|
77
|
+
symbol(&nan, "nan");
|
|
78
|
+
symbol(&nanf, "nanf");
|
|
65
79
|
symbol(&pow10, "pow10");
|
|
66
80
|
symbol(&pow10f, "pow10f");
|
|
67
81
|
symbol(&tanh, "tanh");
|
|
@@ -71,9 +85,8 @@ comptime {
|
|
|
71
85
|
symbol(©sign, "copysign");
|
|
72
86
|
symbol(©signf, "copysignf");
|
|
73
87
|
symbol(&rint, "rint");
|
|
88
|
+
symbol(&rintf, "rintf");
|
|
74
89
|
}
|
|
75
|
-
|
|
76
|
-
symbol(©signl, "copysignl");
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
fn acos(x: f64) callconv(.c) f64 {
|
|
@@ -147,6 +160,58 @@ fn exp10f(x: f32) callconv(.c) f32 {
|
|
|
147
160
|
return math.pow(f32, 10.0, x);
|
|
148
161
|
}
|
|
149
162
|
|
|
163
|
+
fn fdim(x: f64, y: f64) callconv(.c) f64 {
|
|
164
|
+
if (math.isNan(x)) {
|
|
165
|
+
return x;
|
|
166
|
+
}
|
|
167
|
+
if (math.isNan(y)) {
|
|
168
|
+
return y;
|
|
169
|
+
}
|
|
170
|
+
if (x > y) {
|
|
171
|
+
return x - y;
|
|
172
|
+
}
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fn finite(x: f64) callconv(.c) c_int {
|
|
177
|
+
return if (math.isFinite(x)) 1 else 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
fn finitef(x: f32) callconv(.c) c_int {
|
|
181
|
+
return if (math.isFinite(x)) 1 else 0;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
|
|
185
|
+
// libc expects `*e` to be unspecified in this case; an unspecified C value
|
|
186
|
+
// should be a valid value of the relevant type, yet Zig's std
|
|
187
|
+
// implementation sets it to `undefined` -- which can even be nonsense
|
|
188
|
+
// according to the type (int). Therefore, we're setting it to a valid
|
|
189
|
+
// int value in Zig -- a zero.
|
|
190
|
+
//
|
|
191
|
+
// This mirrors the handling of infinities, where libc also expects
|
|
192
|
+
// unspecified for the value of `*e` and Zig std sets it to a zero.
|
|
193
|
+
if (math.isNan(x)) {
|
|
194
|
+
e.* = 0;
|
|
195
|
+
return x;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const r = math.frexp(x);
|
|
199
|
+
e.* = r.exponent;
|
|
200
|
+
return r.significand;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
fn frexp(x: f64, e: *c_int) callconv(.c) f64 {
|
|
204
|
+
return frexpGeneric(f64, x, e);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
fn frexpf(x: f32, e: *c_int) callconv(.c) f32 {
|
|
208
|
+
return frexpGeneric(f32, x, e);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
fn frexpl(x: c_longdouble, e: *c_int) callconv(.c) c_longdouble {
|
|
212
|
+
return frexpGeneric(c_longdouble, x, e);
|
|
213
|
+
}
|
|
214
|
+
|
|
150
215
|
fn hypot(x: f64, y: f64) callconv(.c) f64 {
|
|
151
216
|
return math.hypot(x, y);
|
|
152
217
|
}
|
|
@@ -171,6 +236,14 @@ fn isnanl(x: c_longdouble) callconv(.c) c_int {
|
|
|
171
236
|
return if (math.isNan(x)) 1 else 0;
|
|
172
237
|
}
|
|
173
238
|
|
|
239
|
+
fn lrint(x: f64) callconv(.c) c_long {
|
|
240
|
+
return @intFromFloat(rint(x));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fn lrintf(x: f32) callconv(.c) c_long {
|
|
244
|
+
return @intFromFloat(rintf(x));
|
|
245
|
+
}
|
|
246
|
+
|
|
174
247
|
fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
|
|
175
248
|
if (math.isNegativeInf(x)) {
|
|
176
249
|
iptr.* = -math.inf(T);
|
|
@@ -272,10 +345,6 @@ fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble {
|
|
|
272
345
|
return math.nan(c_longdouble);
|
|
273
346
|
}
|
|
274
347
|
|
|
275
|
-
fn pow(x: f64, y: f64) callconv(.c) f64 {
|
|
276
|
-
return math.pow(f64, x, y);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
348
|
fn pow10(x: f64) callconv(.c) f64 {
|
|
280
349
|
return exp10(x);
|
|
281
350
|
}
|
|
@@ -285,7 +354,7 @@ fn pow10f(x: f32) callconv(.c) f32 {
|
|
|
285
354
|
}
|
|
286
355
|
|
|
287
356
|
fn rint(x: f64) callconv(.c) f64 {
|
|
288
|
-
const toint: f64 = 1.0 /
|
|
357
|
+
const toint: f64 = 1.0 / math.floatEps(f64);
|
|
289
358
|
const a: u64 = @bitCast(x);
|
|
290
359
|
const e = a >> 52 & 0x7ff;
|
|
291
360
|
const s = a >> 63;
|
|
@@ -305,39 +374,70 @@ fn rint(x: f64) callconv(.c) f64 {
|
|
|
305
374
|
return y;
|
|
306
375
|
}
|
|
307
376
|
|
|
308
|
-
|
|
377
|
+
fn rintf(x: f32) callconv(.c) f32 {
|
|
378
|
+
const toint: f32 = 1.0 / math.floatEps(f32);
|
|
379
|
+
const a: u32 = @bitCast(x);
|
|
380
|
+
const e = a >> 23 & 0xff;
|
|
381
|
+
const s = a >> 31;
|
|
382
|
+
var y: f32 = undefined;
|
|
383
|
+
|
|
384
|
+
if (e >= 0x7f + 23) {
|
|
385
|
+
return x;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (s == 1) {
|
|
389
|
+
y = x - toint + toint;
|
|
390
|
+
} else {
|
|
391
|
+
y = x + toint - toint;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (y == 0) {
|
|
395
|
+
return if (s == 1) -0.0 else 0;
|
|
396
|
+
}
|
|
397
|
+
return y;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
fn testRint(comptime T: type) !void {
|
|
401
|
+
const f = switch (T) {
|
|
402
|
+
f32 => rintf,
|
|
403
|
+
f64 => rint,
|
|
404
|
+
else => @compileError("rint not implemented for" ++ @typeName(T)),
|
|
405
|
+
};
|
|
406
|
+
|
|
309
407
|
// Positive numbers round correctly
|
|
310
|
-
try expectEqual(@as(
|
|
311
|
-
try expectEqual(@as(
|
|
408
|
+
try expectEqual(@as(T, 42.0), f(42.2));
|
|
409
|
+
try expectEqual(@as(T, 42.0), f(41.8));
|
|
312
410
|
|
|
313
411
|
// Negative numbers round correctly
|
|
314
|
-
try expectEqual(@as(
|
|
315
|
-
try expectEqual(@as(
|
|
412
|
+
try expectEqual(@as(T, -6.0), f(-5.9));
|
|
413
|
+
try expectEqual(@as(T, -6.0), f(-6.1));
|
|
316
414
|
|
|
317
415
|
// No rounding needed test
|
|
318
|
-
try expectEqual(@as(
|
|
319
|
-
try expectEqual(@as(
|
|
320
|
-
try expectEqual(@as(
|
|
416
|
+
try expectEqual(@as(T, 5.0), f(5.0));
|
|
417
|
+
try expectEqual(@as(T, -10.0), f(-10.0));
|
|
418
|
+
try expectEqual(@as(T, 0.0), f(0.0));
|
|
321
419
|
|
|
322
420
|
// Very large numbers return unchanged
|
|
323
|
-
const large:
|
|
324
|
-
try expectEqual(large,
|
|
325
|
-
try expectEqual(-large,
|
|
421
|
+
const large: T = 9007199254740992.0; // 2^53
|
|
422
|
+
try expectEqual(large, f(large));
|
|
423
|
+
try expectEqual(-large, f(-large));
|
|
326
424
|
|
|
327
425
|
// Small positive numbers round to zero
|
|
328
|
-
const pos_result =
|
|
329
|
-
try
|
|
330
|
-
try expect(@as(u64, @bitCast(pos_result)) == 0);
|
|
426
|
+
const pos_result = f(0.3);
|
|
427
|
+
try expect(math.isPositiveZero(pos_result));
|
|
331
428
|
|
|
332
429
|
// Small negative numbers round to negative zero
|
|
333
|
-
const neg_result =
|
|
334
|
-
try
|
|
335
|
-
const bits: u64 = @bitCast(neg_result);
|
|
336
|
-
try expect((bits >> 63) == 1);
|
|
430
|
+
const neg_result = f(-0.3);
|
|
431
|
+
try expect(math.isNegativeZero(neg_result));
|
|
337
432
|
|
|
338
433
|
// Exact half rounds to nearest even (banker's rounding)
|
|
339
|
-
try expectEqual(@as(
|
|
340
|
-
try expectEqual(@as(
|
|
434
|
+
try expectEqual(@as(T, 2.0), f(2.5));
|
|
435
|
+
try expectEqual(@as(T, 4.0), f(3.5));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
test "rint" {
|
|
439
|
+
try testRint(f32);
|
|
440
|
+
try testRint(f64);
|
|
341
441
|
}
|
|
342
442
|
|
|
343
443
|
fn tanh(x: f64) callconv(.c) f64 {
|
package/c/stropts.zig
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const builtin = @import("builtin");
|
|
2
|
+
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const linux = std.os.linux;
|
|
5
|
+
|
|
6
|
+
const symbol = @import("../c.zig").symbol;
|
|
7
|
+
const errno = @import("../c.zig").errno;
|
|
8
|
+
|
|
9
|
+
comptime {
|
|
10
|
+
if (builtin.target.isMuslLibC()) {
|
|
11
|
+
symbol(&isastream, "isastream");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fn isastream(fd: c_int) callconv(.c) c_int {
|
|
16
|
+
return if (errno(linux.fcntl(fd, linux.F.GETFD, 0)) < 0) -1 else 0;
|
|
17
|
+
}
|