@zigc/lib 0.16.0-test.1 → 0.17.0-dev.131
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/fcntl.zig +6 -1
- package/c/inttypes.zig +0 -10
- package/c/math.zig +138 -114
- package/c/pthread.zig +57 -0
- package/c/search.zig +1 -27
- package/c/stdlib/drand48.zig +0 -57
- package/c/stdlib.zig +0 -100
- package/c/string.zig +20 -7
- package/c/strings.zig +0 -38
- package/c/stropts.zig +17 -0
- package/c/unistd.zig +27 -26
- package/c/wchar.zig +10 -0
- package/c.zig +3 -2
- 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 +8 -7
- package/compiler/aro/aro/Compilation.zig +137 -111
- package/compiler/aro/aro/Diagnostics.zig +21 -17
- package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
- package/compiler/aro/aro/Driver.zig +138 -63
- package/compiler/aro/aro/LangOpts.zig +12 -2
- package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
- package/compiler/aro/aro/Parser.zig +352 -153
- package/compiler/aro/aro/Pragma.zig +3 -2
- package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
- package/compiler/aro/aro/Preprocessor.zig +136 -62
- 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/message.zig +3 -2
- package/compiler/aro/aro/pragmas/once.zig +0 -1
- package/compiler/aro/aro/record_layout.zig +3 -3
- package/compiler/aro/aro/text_literal.zig +3 -2
- package/compiler/aro/assembly_backend/x86_64.zig +7 -8
- 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 -2
- package/compiler/objdump.zig +93 -0
- package/compiler/reduce/Walk.zig +7 -7
- 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 +194 -62
- 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 +369 -127
- package/compiler/translate-c/ast.zig +19 -11
- package/compiler/translate-c/main.zig +76 -17
- package/compiler_rt/cos.zig +140 -53
- package/compiler_rt/divmodei4.zig +40 -17
- package/compiler_rt/exp.zig +1 -6
- package/compiler_rt/exp2.zig +1 -6
- package/compiler_rt/exp_f128.zig +377 -0
- package/compiler_rt/fabs.zig +0 -2
- package/compiler_rt/fma.zig +0 -2
- package/compiler_rt/fmax.zig +0 -2
- package/compiler_rt/fmin.zig +0 -2
- package/compiler_rt/fmod.zig +0 -2
- package/compiler_rt/limb64.zig +1127 -0
- package/compiler_rt/log.zig +0 -2
- package/compiler_rt/log10.zig +0 -2
- package/compiler_rt/log2.zig +0 -2
- package/compiler_rt/long_double.zig +37 -0
- package/compiler_rt/mulXi3.zig +1 -1
- package/compiler_rt/mulo.zig +6 -1
- package/compiler_rt/rem_pio2l.zig +173 -0
- package/compiler_rt/round.zig +0 -2
- package/compiler_rt/sin.zig +139 -56
- package/compiler_rt/sincos.zig +277 -72
- package/compiler_rt/sqrt.zig +0 -2
- package/compiler_rt/ssp.zig +1 -1
- package/compiler_rt/tan.zig +117 -48
- package/compiler_rt/trig.zig +256 -6
- package/compiler_rt/trunc.zig +0 -2
- package/compiler_rt/udivmodei4.zig +28 -0
- package/compiler_rt.zig +2 -0
- package/fuzzer.zig +857 -307
- package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
- package/libc/musl/src/math/pow.c +343 -0
- package/package.json +1 -1
- package/std/Build/Cache.zig +6 -6
- 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 -1
- package/std/Build/Step/ConfigHeader.zig +49 -33
- package/std/Build/Step/InstallArtifact.zig +18 -0
- package/std/Build/Step/Run.zig +538 -89
- package/std/Build/Step/TranslateC.zig +0 -6
- package/std/Build/Step.zig +10 -19
- package/std/Build/WebServer.zig +31 -19
- package/std/Build/abi.zig +47 -11
- package/std/Build.zig +17 -17
- package/std/Io/Dir.zig +7 -2
- package/std/Io/Dispatch.zig +5 -13
- package/std/Io/File/Reader.zig +3 -1
- package/std/Io/File/Writer.zig +8 -6
- package/std/Io/File.zig +1 -0
- package/std/Io/Kqueue.zig +2 -2
- package/std/Io/Reader.zig +8 -9
- package/std/Io/Semaphore.zig +112 -17
- package/std/Io/Terminal.zig +1 -1
- package/std/Io/Threaded.zig +352 -180
- package/std/Io/Uring.zig +15 -16
- package/std/Io/Writer.zig +46 -42
- package/std/Io/net.zig +11 -11
- package/std/Io.zig +1052 -20
- package/std/SemanticVersion.zig +1 -1
- package/std/Target/Query.zig +2 -2
- package/std/Target.zig +53 -7
- package/std/Thread.zig +8 -3
- package/std/array_hash_map.zig +105 -573
- package/std/array_list.zig +22 -31
- package/std/bit_set.zig +22 -6
- package/std/builtin/assembly.zig +68 -0
- package/std/builtin.zig +4 -0
- package/std/c/haiku.zig +3 -0
- package/std/c/serenity.zig +1 -6
- package/std/c.zig +106 -24
- package/std/compress/flate/Compress.zig +3 -3
- package/std/compress/flate/Decompress.zig +2 -3
- package/std/compress/zstd/Decompress.zig +2 -4
- package/std/crypto/Certificate/Bundle.zig +15 -1
- package/std/crypto/Certificate.zig +13 -1
- package/std/crypto/ascon.zig +75 -33
- package/std/crypto/codecs/asn1/Oid.zig +12 -1
- package/std/crypto/codecs/asn1.zig +33 -18
- package/std/crypto/codecs/base64_hex_ct.zig +16 -8
- package/std/crypto/ml_kem.zig +2 -9
- package/std/crypto/tls/Client.zig +79 -4
- package/std/crypto/tls.zig +1 -1
- package/std/crypto.zig +1 -0
- 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 +540 -37
- 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 +181 -66
- package/std/enums.zig +25 -19
- package/std/fmt.zig +8 -3
- package/std/fs/path.zig +6 -4
- package/std/heap/ArenaAllocator.zig +145 -154
- package/std/heap/BufferFirstAllocator.zig +165 -0
- package/std/heap/debug_allocator.zig +7 -7
- package/std/heap.zig +2 -126
- package/std/http/Client.zig +31 -30
- package/std/http.zig +14 -13
- package/std/json/Scanner.zig +2 -2
- 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 +2 -18
- package/std/os/linux/IoUring.zig +2 -0
- package/std/os/linux/aarch64.zig +41 -12
- package/std/os/linux/arc.zig +173 -0
- package/std/os/linux/arm.zig +41 -12
- package/std/os/linux/hexagon.zig +33 -11
- package/std/os/linux/loongarch32.zig +41 -13
- package/std/os/linux/loongarch64.zig +41 -12
- package/std/os/linux/m68k.zig +41 -13
- package/std/os/linux/mips.zig +67 -36
- package/std/os/linux/mips64.zig +60 -29
- package/std/os/linux/mipsn32.zig +60 -29
- package/std/os/linux/or1k.zig +41 -12
- package/std/os/linux/powerpc.zig +41 -12
- package/std/os/linux/powerpc64.zig +41 -12
- package/std/os/linux/riscv32.zig +41 -12
- package/std/os/linux/riscv64.zig +41 -12
- package/std/os/linux/s390x.zig +44 -7
- package/std/os/linux/sparc64.zig +83 -52
- package/std/os/linux/thumb.zig +52 -36
- package/std/os/linux/x32.zig +41 -12
- package/std/os/linux/x86.zig +42 -13
- package/std/os/linux/x86_64.zig +41 -12
- package/std/os/linux.zig +419 -438
- package/std/os/uefi/tables/boot_services.zig +9 -8
- package/std/os/windows.zig +2 -2
- package/std/os.zig +41 -0
- 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/process.zig +1 -1
- package/std/sort.zig +3 -3
- 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 +187 -459
- package/std/zig/Ast.zig +0 -4
- package/std/zig/AstGen.zig +86 -103
- package/std/zig/AstRlAnnotate.zig +0 -11
- package/std/zig/AstSmith.zig +2602 -0
- package/std/zig/BuiltinFn.zig +0 -32
- package/std/zig/Client.zig +8 -3
- package/std/zig/LibCInstallation.zig +4 -3
- package/std/zig/Parse.zig +90 -81
- package/std/zig/Server.zig +26 -0
- package/std/zig/WindowsSdk.zig +13 -13
- package/std/zig/Zir.zig +66 -62
- package/std/zig/ZonGen.zig +6 -5
- package/std/zig/c_translation/helpers.zig +14 -9
- package/std/zig/llvm/Builder.zig +119 -60
- package/std/zig/system.zig +20 -4
- package/std/zig/tokenizer.zig +2 -1
- package/std/zig.zig +7 -10
- package/std/zip.zig +5 -5
- package/zig.h +340 -1
- 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/fdiml.c +0 -24
- 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/mingw/winpthreads/spinlock.c +0 -82
- package/libc/musl/src/legacy/isastream.c +0 -7
- package/libc/musl/src/legacy/valloc.c +0 -8
- package/libc/musl/src/linux/tee.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/fdimf.c +0 -10
- package/libc/musl/src/math/fdiml.c +0 -18
- 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/musl/src/string/strdup.c +0 -10
- package/libc/musl/src/string/strndup.c +0 -12
- package/libc/musl/src/string/wcsdup.c +0 -10
- package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
- package/libc/musl/src/thread/pthread_spin_init.c +0 -6
- package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
- package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
- package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
- package/libc/musl/src/unistd/dup2.c +0 -20
- package/libc/musl/src/unistd/dup3.c +0 -26
- package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
- package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
- package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
- package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
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/fcntl.zig
CHANGED
|
@@ -12,11 +12,12 @@ comptime {
|
|
|
12
12
|
symbol(&fallocateLinux, "fallocate");
|
|
13
13
|
symbol(&posix_fadviseLinux, "posix_fadvise");
|
|
14
14
|
symbol(&posix_fallocateLinux, "posix_fallocate");
|
|
15
|
+
symbol(&teeLinux, "tee");
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
fn fallocateLinux(fd: c_int, mode: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
|
|
19
|
-
return errno(linux.fallocate(fd, mode, offset, len));
|
|
20
|
+
return errno(linux.fallocate(fd, @bitCast(mode), offset, len));
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callconv(.c) c_int {
|
|
@@ -26,3 +27,7 @@ fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callc
|
|
|
26
27
|
fn posix_fallocateLinux(fd: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
|
|
27
28
|
return errno(linux.fallocate(fd, 0, offset, len));
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
fn teeLinux(src: c_int, dest: c_int, len: usize, flags: c_uint) callconv(.c) isize {
|
|
32
|
+
return errno(linux.tee(src, dest, len, flags));
|
|
33
|
+
}
|
package/c/inttypes.zig
CHANGED
|
@@ -24,13 +24,3 @@ fn imaxdiv(a: intmax_t, b: intmax_t) callconv(.c) imaxdiv_t {
|
|
|
24
24
|
.rem = @rem(a, b),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
test imaxabs {
|
|
29
|
-
const val: intmax_t = -10;
|
|
30
|
-
try std.testing.expectEqual(10, imaxabs(val));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test imaxdiv {
|
|
34
|
-
const expected: imaxdiv_t = .{ .quot = 9, .rem = 0 };
|
|
35
|
-
try std.testing.expectEqual(expected, imaxdiv(9, 1));
|
|
36
|
-
}
|
package/c/math.zig
CHANGED
|
@@ -2,10 +2,6 @@ const builtin = @import("builtin");
|
|
|
2
2
|
|
|
3
3
|
const std = @import("std");
|
|
4
4
|
const math = std.math;
|
|
5
|
-
const expect = std.testing.expect;
|
|
6
|
-
const expectEqual = std.testing.expectEqual;
|
|
7
|
-
const expectApproxEqAbs = std.testing.expectApproxEqAbs;
|
|
8
|
-
const expectApproxEqRel = std.testing.expectApproxEqRel;
|
|
9
5
|
|
|
10
6
|
const symbol = @import("../c.zig").symbol;
|
|
11
7
|
|
|
@@ -35,33 +31,49 @@ comptime {
|
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
38
|
-
symbol(&
|
|
34
|
+
symbol(&frexpf, "frexpf");
|
|
35
|
+
symbol(&frexpl, "frexpl");
|
|
39
36
|
symbol(&hypotf, "hypotf");
|
|
40
37
|
symbol(&hypotl, "hypotl");
|
|
41
|
-
symbol(&modff, "modff");
|
|
42
38
|
symbol(&modfl, "modfl");
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
42
|
+
symbol(&atanl, "atanl");
|
|
43
|
+
symbol(©signl, "copysignl");
|
|
44
|
+
symbol(&fdiml, "fdiml");
|
|
45
45
|
symbol(&nanl, "nanl");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if ((builtin.target.isMinGW() and builtin.cpu.arch == .x86) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
49
|
+
symbol(&acosf, "acosf");
|
|
50
|
+
symbol(&atanf, "atanf");
|
|
51
|
+
symbol(&coshf, "coshf");
|
|
52
|
+
symbol(&modff, "modff");
|
|
46
53
|
symbol(&tanhf, "tanhf");
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
50
57
|
symbol(&acos, "acos");
|
|
51
|
-
symbol(&acosf, "acosf");
|
|
52
58
|
symbol(&acoshf, "acoshf");
|
|
53
59
|
symbol(&asin, "asin");
|
|
54
60
|
symbol(&atan, "atan");
|
|
55
|
-
symbol(&atanf, "atanf");
|
|
56
|
-
symbol(&atanl, "atanl");
|
|
57
61
|
symbol(&cbrt, "cbrt");
|
|
58
62
|
symbol(&cbrtf, "cbrtf");
|
|
59
63
|
symbol(&cosh, "cosh");
|
|
60
64
|
symbol(&exp10, "exp10");
|
|
61
65
|
symbol(&exp10f, "exp10f");
|
|
66
|
+
symbol(&fdim, "fdim");
|
|
67
|
+
symbol(&fdimf, "fdimf");
|
|
68
|
+
symbol(&finite, "finite");
|
|
69
|
+
symbol(&finitef, "finitef");
|
|
70
|
+
symbol(&frexp, "frexp");
|
|
62
71
|
symbol(&hypot, "hypot");
|
|
72
|
+
symbol(&lrint, "lrint");
|
|
73
|
+
symbol(&lrintf, "lrintf");
|
|
63
74
|
symbol(&modf, "modf");
|
|
64
|
-
symbol(&
|
|
75
|
+
symbol(&nan, "nan");
|
|
76
|
+
symbol(&nanf, "nanf");
|
|
65
77
|
symbol(&pow10, "pow10");
|
|
66
78
|
symbol(&pow10f, "pow10f");
|
|
67
79
|
symbol(&tanh, "tanh");
|
|
@@ -71,9 +83,8 @@ comptime {
|
|
|
71
83
|
symbol(©sign, "copysign");
|
|
72
84
|
symbol(©signf, "copysignf");
|
|
73
85
|
symbol(&rint, "rint");
|
|
86
|
+
symbol(&rintf, "rintf");
|
|
74
87
|
}
|
|
75
|
-
|
|
76
|
-
symbol(©signl, "copysignl");
|
|
77
88
|
}
|
|
78
89
|
|
|
79
90
|
fn acos(x: f64) callconv(.c) f64 {
|
|
@@ -101,13 +112,9 @@ fn atanf(x: f32) callconv(.c) f32 {
|
|
|
101
112
|
}
|
|
102
113
|
|
|
103
114
|
fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
104
|
-
return switch (@typeInfo(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
64 => math.atan(@as(f64, @floatCast(x))),
|
|
108
|
-
80 => math.atan(@as(f80, @floatCast(x))),
|
|
109
|
-
128 => math.atan(@as(f128, @floatCast(x))),
|
|
110
|
-
else => unreachable,
|
|
115
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
116
|
+
64 => std.c.atan(x),
|
|
117
|
+
else => math.atan(x),
|
|
111
118
|
};
|
|
112
119
|
}
|
|
113
120
|
|
|
@@ -128,7 +135,10 @@ fn copysignf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
131
|
-
return
|
|
138
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
139
|
+
64 => std.c.copysign(x, y),
|
|
140
|
+
else => math.copysign(x, y),
|
|
141
|
+
};
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
fn cosh(x: f64) callconv(.c) f64 {
|
|
@@ -147,6 +157,75 @@ fn exp10f(x: f32) callconv(.c) f32 {
|
|
|
147
157
|
return math.pow(f32, 10.0, x);
|
|
148
158
|
}
|
|
149
159
|
|
|
160
|
+
fn fdimGeneric(comptime T: type, x: T, y: T) T {
|
|
161
|
+
if (math.isNan(x))
|
|
162
|
+
return x;
|
|
163
|
+
|
|
164
|
+
if (math.isNan(y))
|
|
165
|
+
return y;
|
|
166
|
+
|
|
167
|
+
if (x > y)
|
|
168
|
+
return x - y;
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
fn fdim(x: f64, y: f64) callconv(.c) f64 {
|
|
173
|
+
return fdimGeneric(f64, x, y);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fn fdimf(x: f32, y: f32) callconv(.c) f32 {
|
|
177
|
+
return fdimGeneric(f32, x, y);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
181
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
182
|
+
64 => std.c.fdim(x, y),
|
|
183
|
+
else => fdimGeneric(c_longdouble, x, y),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fn finite(x: f64) callconv(.c) c_int {
|
|
188
|
+
return @intFromBool(math.isFinite(x));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
fn finitef(x: f32) callconv(.c) c_int {
|
|
192
|
+
return @intFromBool(math.isFinite(x));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
|
|
196
|
+
// libc expects `*e` to be unspecified in this case; an unspecified C value
|
|
197
|
+
// should be a valid value of the relevant type, yet Zig's std
|
|
198
|
+
// implementation sets it to `undefined` -- which can even be nonsense
|
|
199
|
+
// according to the type (int). Therefore, we're setting it to a valid
|
|
200
|
+
// int value in Zig -- a zero.
|
|
201
|
+
//
|
|
202
|
+
// This mirrors the handling of infinities, where libc also expects
|
|
203
|
+
// unspecified for the value of `*e` and Zig std sets it to a zero.
|
|
204
|
+
if (math.isNan(x)) {
|
|
205
|
+
e.* = 0;
|
|
206
|
+
return x;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const r = math.frexp(x);
|
|
210
|
+
e.* = r.exponent;
|
|
211
|
+
return r.significand;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
fn frexp(x: f64, e: *c_int) callconv(.c) f64 {
|
|
215
|
+
return frexpGeneric(f64, x, e);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
fn frexpf(x: f32, e: *c_int) callconv(.c) f32 {
|
|
219
|
+
return frexpGeneric(f32, x, e);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fn frexpl(x: c_longdouble, e: *c_int) callconv(.c) c_longdouble {
|
|
223
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
224
|
+
64 => std.c.frexp(x, e),
|
|
225
|
+
else => frexpGeneric(c_longdouble, x, e),
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
150
229
|
fn hypot(x: f64, y: f64) callconv(.c) f64 {
|
|
151
230
|
return math.hypot(x, y);
|
|
152
231
|
}
|
|
@@ -156,19 +235,30 @@ fn hypotf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
156
235
|
}
|
|
157
236
|
|
|
158
237
|
fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
159
|
-
return
|
|
238
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
239
|
+
64 => std.c.hypot(x, y),
|
|
240
|
+
else => math.hypot(x, y),
|
|
241
|
+
};
|
|
160
242
|
}
|
|
161
243
|
|
|
162
244
|
fn isnan(x: f64) callconv(.c) c_int {
|
|
163
|
-
return
|
|
245
|
+
return @intFromBool(math.isNan(x));
|
|
164
246
|
}
|
|
165
247
|
|
|
166
248
|
fn isnanf(x: f32) callconv(.c) c_int {
|
|
167
|
-
return
|
|
249
|
+
return @intFromBool(math.isNan(x));
|
|
168
250
|
}
|
|
169
251
|
|
|
170
252
|
fn isnanl(x: c_longdouble) callconv(.c) c_int {
|
|
171
|
-
return
|
|
253
|
+
return @intFromBool(math.isNan(x));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
fn lrint(x: f64) callconv(.c) c_long {
|
|
257
|
+
return @intFromFloat(rint(x));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
fn lrintf(x: f32) callconv(.c) c_long {
|
|
261
|
+
return @intFromFloat(rintf(x));
|
|
172
262
|
}
|
|
173
263
|
|
|
174
264
|
fn modfGeneric(comptime T: type, x: T, iptr: *T) T {
|
|
@@ -204,60 +294,10 @@ fn modff(x: f32, iptr: *f32) callconv(.c) f32 {
|
|
|
204
294
|
}
|
|
205
295
|
|
|
206
296
|
fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble {
|
|
207
|
-
return
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
fn testModf(comptime T: type) !void {
|
|
211
|
-
// Choose the appropriate `modf` impl to test based on type
|
|
212
|
-
const f = switch (T) {
|
|
213
|
-
f32 => modff,
|
|
214
|
-
f64 => modf,
|
|
215
|
-
c_longdouble => modfl,
|
|
216
|
-
else => @compileError("modf not implemented for " ++ @typeName(T)),
|
|
297
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
298
|
+
64 => std.c.modf(x, iptr),
|
|
299
|
+
else => modfGeneric(c_longdouble, x, iptr),
|
|
217
300
|
};
|
|
218
|
-
|
|
219
|
-
var int: T = undefined;
|
|
220
|
-
const iptr = ∫
|
|
221
|
-
const eps_val: comptime_float = @max(1e-6, math.floatEps(T));
|
|
222
|
-
|
|
223
|
-
const normal_frac = f(@as(T, 1234.567), iptr);
|
|
224
|
-
// Account for precision error
|
|
225
|
-
const expected = 1234.567 - @as(T, 1234);
|
|
226
|
-
try expectApproxEqAbs(expected, normal_frac, eps_val);
|
|
227
|
-
try expectApproxEqRel(@as(T, 1234.0), iptr.*, eps_val);
|
|
228
|
-
|
|
229
|
-
// When `x` is a NaN, NaN is returned and `*iptr` is set to NaN
|
|
230
|
-
const nan_frac = f(math.nan(T), iptr);
|
|
231
|
-
try expect(math.isNan(nan_frac));
|
|
232
|
-
try expect(math.isNan(iptr.*));
|
|
233
|
-
|
|
234
|
-
// When `x` is positive infinity, +0 is returned and `*iptr` is set to
|
|
235
|
-
// positive infinity
|
|
236
|
-
const pos_zero_frac = f(math.inf(T), iptr);
|
|
237
|
-
try expect(math.isPositiveZero(pos_zero_frac));
|
|
238
|
-
try expect(math.isPositiveInf(iptr.*));
|
|
239
|
-
|
|
240
|
-
// When `x` is negative infinity, -0 is returned and `*iptr` is set to
|
|
241
|
-
// negative infinity
|
|
242
|
-
const neg_zero_frac = f(-math.inf(T), iptr);
|
|
243
|
-
try expect(math.isNegativeZero(neg_zero_frac));
|
|
244
|
-
try expect(math.isNegativeInf(iptr.*));
|
|
245
|
-
|
|
246
|
-
// Return -0 when `x` is a negative integer
|
|
247
|
-
const nz_frac = f(@as(T, -1000.0), iptr);
|
|
248
|
-
try expect(math.isNegativeZero(nz_frac));
|
|
249
|
-
try expectEqual(@as(T, -1000.0), iptr.*);
|
|
250
|
-
|
|
251
|
-
// Return +0 when `x` is a positive integer
|
|
252
|
-
const pz_frac = f(@as(T, 1000.0), iptr);
|
|
253
|
-
try expect(math.isPositiveZero(pz_frac));
|
|
254
|
-
try expectEqual(@as(T, 1000.0), iptr.*);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
test "modf" {
|
|
258
|
-
try testModf(f32);
|
|
259
|
-
try testModf(f64);
|
|
260
|
-
try testModf(c_longdouble);
|
|
261
301
|
}
|
|
262
302
|
|
|
263
303
|
fn nan(_: [*:0]const c_char) callconv(.c) f64 {
|
|
@@ -272,10 +312,6 @@ fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble {
|
|
|
272
312
|
return math.nan(c_longdouble);
|
|
273
313
|
}
|
|
274
314
|
|
|
275
|
-
fn pow(x: f64, y: f64) callconv(.c) f64 {
|
|
276
|
-
return math.pow(f64, x, y);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
315
|
fn pow10(x: f64) callconv(.c) f64 {
|
|
280
316
|
return exp10(x);
|
|
281
317
|
}
|
|
@@ -285,7 +321,7 @@ fn pow10f(x: f32) callconv(.c) f32 {
|
|
|
285
321
|
}
|
|
286
322
|
|
|
287
323
|
fn rint(x: f64) callconv(.c) f64 {
|
|
288
|
-
const toint: f64 = 1.0 /
|
|
324
|
+
const toint: f64 = 1.0 / math.floatEps(f64);
|
|
289
325
|
const a: u64 = @bitCast(x);
|
|
290
326
|
const e = a >> 52 & 0x7ff;
|
|
291
327
|
const s = a >> 63;
|
|
@@ -305,39 +341,27 @@ fn rint(x: f64) callconv(.c) f64 {
|
|
|
305
341
|
return y;
|
|
306
342
|
}
|
|
307
343
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
try expectEqual(@as(f64, -6.0), rint(-5.9));
|
|
315
|
-
try expectEqual(@as(f64, -6.0), rint(-6.1));
|
|
316
|
-
|
|
317
|
-
// No rounding needed test
|
|
318
|
-
try expectEqual(@as(f64, 5.0), rint(5.0));
|
|
319
|
-
try expectEqual(@as(f64, -10.0), rint(-10.0));
|
|
320
|
-
try expectEqual(@as(f64, 0.0), rint(0.0));
|
|
344
|
+
fn rintf(x: f32) callconv(.c) f32 {
|
|
345
|
+
const toint: f32 = 1.0 / math.floatEps(f32);
|
|
346
|
+
const a: u32 = @bitCast(x);
|
|
347
|
+
const e = a >> 23 & 0xff;
|
|
348
|
+
const s = a >> 31;
|
|
349
|
+
var y: f32 = undefined;
|
|
321
350
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
try expectEqual(-large, rint(-large));
|
|
326
|
-
|
|
327
|
-
// Small positive numbers round to zero
|
|
328
|
-
const pos_result = rint(0.3);
|
|
329
|
-
try expectEqual(@as(f64, 0.0), pos_result);
|
|
330
|
-
try expect(@as(u64, @bitCast(pos_result)) == 0);
|
|
351
|
+
if (e >= 0x7f + 23) {
|
|
352
|
+
return x;
|
|
353
|
+
}
|
|
331
354
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
355
|
+
if (s == 1) {
|
|
356
|
+
y = x - toint + toint;
|
|
357
|
+
} else {
|
|
358
|
+
y = x + toint - toint;
|
|
359
|
+
}
|
|
337
360
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
361
|
+
if (y == 0) {
|
|
362
|
+
return if (s == 1) -0.0 else 0;
|
|
363
|
+
}
|
|
364
|
+
return y;
|
|
341
365
|
}
|
|
342
366
|
|
|
343
367
|
fn tanh(x: f64) callconv(.c) f64 {
|
package/c/pthread.zig
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const builtin = @import("builtin");
|
|
2
|
+
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const c = std.c;
|
|
5
|
+
|
|
6
|
+
const symbol = @import("../c.zig").symbol;
|
|
7
|
+
|
|
8
|
+
comptime {
|
|
9
|
+
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC() or builtin.target.isMinGW()) {
|
|
10
|
+
symbol(&pthread_spin_init, "pthread_spin_init");
|
|
11
|
+
symbol(&pthread_spin_destroy, "pthread_spin_destroy");
|
|
12
|
+
symbol(&pthread_spin_trylock, "pthread_spin_trylock");
|
|
13
|
+
symbol(&pthread_spin_lock, "pthread_spin_lock");
|
|
14
|
+
symbol(&pthread_spin_unlock, "pthread_spin_unlock");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const SpinLock = enum(c.pthread_spinlock_t) {
|
|
19
|
+
unlocked = if (builtin.target.isMinGW()) -1 else 0,
|
|
20
|
+
locked = if (builtin.target.isMinGW()) 0 else @intFromEnum(c.E.BUSY),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
fn pthread_spin_init(s: *c.pthread_spinlock_t, pshared: c_int) callconv(.c) c_int {
|
|
24
|
+
_ = pshared;
|
|
25
|
+
const spin: *SpinLock = @ptrCast(s);
|
|
26
|
+
spin.* = .unlocked;
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fn pthread_spin_destroy(s: *c.pthread_spinlock_t) callconv(.c) c_int {
|
|
31
|
+
const spin: *SpinLock = @ptrCast(s);
|
|
32
|
+
spin.* = undefined;
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn pthread_spin_trylock(s: *c.pthread_spinlock_t) callconv(.c) c_int {
|
|
37
|
+
const spin: *SpinLock = @ptrCast(s);
|
|
38
|
+
return if (@cmpxchgStrong(SpinLock, spin, .unlocked, .locked, .acquire, .monotonic)) |_| @intFromEnum(c.E.BUSY) else 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn pthread_spin_lock(s: *c.pthread_spinlock_t) callconv(.c) c_int {
|
|
42
|
+
const spin: *SpinLock = @ptrCast(s);
|
|
43
|
+
if (builtin.single_threaded and @atomicLoad(SpinLock, spin, .monotonic) == .locked) return @intFromEnum(c.E.DEADLK);
|
|
44
|
+
|
|
45
|
+
while (@cmpxchgWeak(SpinLock, spin, .unlocked, .locked, .acquire, .monotonic)) |_| {
|
|
46
|
+
std.atomic.spinLoopHint();
|
|
47
|
+
}
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn pthread_spin_unlock(s: *c.pthread_spinlock_t) callconv(.c) c_int {
|
|
52
|
+
const spin: *SpinLock = @ptrCast(s);
|
|
53
|
+
|
|
54
|
+
// "The results are undefined if the lock is not held by the calling thread"
|
|
55
|
+
std.debug.assert(@atomicRmw(SpinLock, spin, .Xchg, .unlocked, .release) == .locked);
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
package/c/search.zig
CHANGED
|
@@ -9,6 +9,7 @@ comptime {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/// Not defined in `std.c` because C headers don't either.
|
|
12
13
|
const Node = extern struct {
|
|
13
14
|
next: ?*Node,
|
|
14
15
|
prev: ?*Node,
|
|
@@ -38,30 +39,3 @@ fn remque(element: *anyopaque) callconv(.c) void {
|
|
|
38
39
|
if (e.next) |next| next.prev = e.prev;
|
|
39
40
|
if (e.prev) |prev| prev.next = e.next;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
test "insque and remque" {
|
|
43
|
-
var first = Node{ .next = null, .prev = null };
|
|
44
|
-
var second = Node{ .next = null, .prev = null };
|
|
45
|
-
var third = Node{ .next = null, .prev = null };
|
|
46
|
-
|
|
47
|
-
insque(&first, null);
|
|
48
|
-
try std.testing.expectEqual(@as(?*Node, null), first.next);
|
|
49
|
-
try std.testing.expectEqual(@as(?*Node, null), first.prev);
|
|
50
|
-
|
|
51
|
-
insque(&second, &first);
|
|
52
|
-
try std.testing.expectEqual(@as(?*Node, &second), first.next);
|
|
53
|
-
try std.testing.expectEqual(@as(?*Node, &first), second.prev);
|
|
54
|
-
|
|
55
|
-
insque(&third, &first);
|
|
56
|
-
try std.testing.expectEqual(@as(?*Node, &third), first.next);
|
|
57
|
-
try std.testing.expectEqual(@as(?*Node, &second), third.next);
|
|
58
|
-
try std.testing.expectEqual(@as(?*Node, &first), third.prev);
|
|
59
|
-
try std.testing.expectEqual(@as(?*Node, &third), second.prev);
|
|
60
|
-
|
|
61
|
-
remque(&third);
|
|
62
|
-
try std.testing.expectEqual(@as(?*Node, &second), first.next);
|
|
63
|
-
try std.testing.expectEqual(@as(?*Node, &first), second.prev);
|
|
64
|
-
|
|
65
|
-
remque(&second);
|
|
66
|
-
try std.testing.expectEqual(@as(?*Node, null), first.next);
|
|
67
|
-
}
|
package/c/stdlib/drand48.zig
CHANGED
|
@@ -90,60 +90,3 @@ fn srand48(seedval: c_long) callconv(.c) void {
|
|
|
90
90
|
const xi = (@as(u32, @truncate(@as(c_ulong, @bitCast(seedval)))) << 16) | 0x330E;
|
|
91
91
|
lcg = .init(xi, default_multiplier, default_addend);
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
test erand48 {
|
|
95
|
-
var xsubi: [3]c_ushort = .{ 37174, 64810, 11603 };
|
|
96
|
-
|
|
97
|
-
try std.testing.expectApproxEqAbs(0.8965, erand48(&xsubi), 0.0005);
|
|
98
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 22537, 47966, 58735 }, &xsubi);
|
|
99
|
-
|
|
100
|
-
try std.testing.expectApproxEqAbs(0.3375, erand48(&xsubi), 0.0005);
|
|
101
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 37344, 32911, 22119 }, &xsubi);
|
|
102
|
-
|
|
103
|
-
try std.testing.expectApproxEqAbs(0.6475, erand48(&xsubi), 0.0005);
|
|
104
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 23659, 29872, 42445 }, &xsubi);
|
|
105
|
-
|
|
106
|
-
try std.testing.expectApproxEqAbs(0.5005, erand48(&xsubi), 0.0005);
|
|
107
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 31642, 7875, 32802 }, &xsubi);
|
|
108
|
-
|
|
109
|
-
try std.testing.expectApproxEqAbs(0.5065, erand48(&xsubi), 0.0005);
|
|
110
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 64669, 14399, 33170 }, &xsubi);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
test jrand48 {
|
|
114
|
-
var xsubi: [3]c_ushort = .{ 25175, 11052, 45015 };
|
|
115
|
-
|
|
116
|
-
try std.testing.expectEqual(1699503220, jrand48(&xsubi));
|
|
117
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 2326, 23668, 25932 }, &xsubi);
|
|
118
|
-
|
|
119
|
-
try std.testing.expectEqual(-992276007, jrand48(&xsubi));
|
|
120
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 41577, 4569, 50395 }, &xsubi);
|
|
121
|
-
|
|
122
|
-
try std.testing.expectEqual(-19535776, jrand48(&xsubi));
|
|
123
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 31936, 59488, 65237 }, &xsubi);
|
|
124
|
-
|
|
125
|
-
try std.testing.expectEqual(79438377, jrand48(&xsubi));
|
|
126
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 40395, 8745, 1212 }, &xsubi);
|
|
127
|
-
|
|
128
|
-
try std.testing.expectEqual(-1258917728, jrand48(&xsubi));
|
|
129
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 37242, 28832, 46326 }, &xsubi);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
test nrand48 {
|
|
133
|
-
var xsubi: [3]c_ushort = .{ 546, 33817, 23389 };
|
|
134
|
-
|
|
135
|
-
try std.testing.expectEqual(914920692, nrand48(&xsubi));
|
|
136
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 29829, 10728, 27921 }, &xsubi);
|
|
137
|
-
|
|
138
|
-
try std.testing.expectEqual(754104482, nrand48(&xsubi));
|
|
139
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 6828, 28997, 23013 }, &xsubi);
|
|
140
|
-
|
|
141
|
-
try std.testing.expectEqual(609453945, nrand48(&xsubi));
|
|
142
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 58183, 3826, 18599 }, &xsubi);
|
|
143
|
-
|
|
144
|
-
try std.testing.expectEqual(1878644360, nrand48(&xsubi));
|
|
145
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 36678, 44304, 57331 }, &xsubi);
|
|
146
|
-
|
|
147
|
-
try std.testing.expectEqual(2114923686, nrand48(&xsubi));
|
|
148
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 58585, 22861, 64542 }, &xsubi);
|
|
149
|
-
}
|
package/c/stdlib.zig
CHANGED
|
@@ -294,103 +294,3 @@ fn bsearch(key: *const anyopaque, base: *const anyopaque, n: usize, size: usize,
|
|
|
294
294
|
}
|
|
295
295
|
return null;
|
|
296
296
|
}
|
|
297
|
-
|
|
298
|
-
test abs {
|
|
299
|
-
const val: c_int = -10;
|
|
300
|
-
try std.testing.expectEqual(10, abs(val));
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
test labs {
|
|
304
|
-
const val: c_long = -10;
|
|
305
|
-
try std.testing.expectEqual(10, labs(val));
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
test llabs {
|
|
309
|
-
const val: c_longlong = -10;
|
|
310
|
-
try std.testing.expectEqual(10, llabs(val));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
test div {
|
|
314
|
-
const expected: div_t = .{ .quot = 5, .rem = 5 };
|
|
315
|
-
try std.testing.expectEqual(expected, div(55, 10));
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
test ldiv {
|
|
319
|
-
const expected: ldiv_t = .{ .quot = -6, .rem = 2 };
|
|
320
|
-
try std.testing.expectEqual(expected, ldiv(38, -6));
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
test lldiv {
|
|
324
|
-
const expected: lldiv_t = .{ .quot = 1, .rem = 2 };
|
|
325
|
-
try std.testing.expectEqual(expected, lldiv(5, 3));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
test atoi {
|
|
329
|
-
try std.testing.expectEqual(0, atoi(@ptrCast("stop42true")));
|
|
330
|
-
try std.testing.expectEqual(42, atoi(@ptrCast("42true")));
|
|
331
|
-
try std.testing.expectEqual(-1, atoi(@ptrCast("-01")));
|
|
332
|
-
try std.testing.expectEqual(1, atoi(@ptrCast("+001")));
|
|
333
|
-
try std.testing.expectEqual(100, atoi(@ptrCast(" 100")));
|
|
334
|
-
try std.testing.expectEqual(500, atoi(@ptrCast("000000000000500")));
|
|
335
|
-
try std.testing.expectEqual(1111, atoi(@ptrCast("0000000000001111_0000")));
|
|
336
|
-
try std.testing.expectEqual(0, atoi(@ptrCast("0xAA")));
|
|
337
|
-
try std.testing.expectEqual(700, atoi(@ptrCast("700B")));
|
|
338
|
-
try std.testing.expectEqual(32453, atoi(@ptrCast("+32453more")));
|
|
339
|
-
try std.testing.expectEqual(std.math.maxInt(c_int), atoi(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_int)}))));
|
|
340
|
-
try std.testing.expectEqual(std.math.minInt(c_int), atoi(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_int)}))));
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
test atol {
|
|
344
|
-
try std.testing.expectEqual(0, atol(@ptrCast("stop42true")));
|
|
345
|
-
try std.testing.expectEqual(42, atol(@ptrCast("42true")));
|
|
346
|
-
try std.testing.expectEqual(-1, atol(@ptrCast("-01")));
|
|
347
|
-
try std.testing.expectEqual(1, atol(@ptrCast("+001")));
|
|
348
|
-
try std.testing.expectEqual(100, atol(@ptrCast(" 100")));
|
|
349
|
-
try std.testing.expectEqual(500, atol(@ptrCast("000000000000500")));
|
|
350
|
-
try std.testing.expectEqual(1111, atol(@ptrCast("0000000000001111_0000")));
|
|
351
|
-
try std.testing.expectEqual(0, atol(@ptrCast("0xAA")));
|
|
352
|
-
try std.testing.expectEqual(700, atol(@ptrCast("700B")));
|
|
353
|
-
try std.testing.expectEqual(32453, atol(@ptrCast("+32453more")));
|
|
354
|
-
try std.testing.expectEqual(std.math.maxInt(c_long), atol(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_long)}))));
|
|
355
|
-
try std.testing.expectEqual(std.math.minInt(c_long), atol(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_long)}))));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
test atoll {
|
|
359
|
-
try std.testing.expectEqual(0, atoll(@ptrCast("stop42true")));
|
|
360
|
-
try std.testing.expectEqual(42, atoll(@ptrCast("42true")));
|
|
361
|
-
try std.testing.expectEqual(-1, atoll(@ptrCast("-01")));
|
|
362
|
-
try std.testing.expectEqual(1, atoll(@ptrCast("+001")));
|
|
363
|
-
try std.testing.expectEqual(100, atoll(@ptrCast(" 100")));
|
|
364
|
-
try std.testing.expectEqual(500, atoll(@ptrCast("000000000000500")));
|
|
365
|
-
try std.testing.expectEqual(1111, atoll(@ptrCast("0000000000001111_0000")));
|
|
366
|
-
try std.testing.expectEqual(0, atoll(@ptrCast("0xAA")));
|
|
367
|
-
try std.testing.expectEqual(700, atoll(@ptrCast("700B")));
|
|
368
|
-
try std.testing.expectEqual(32453, atoll(@ptrCast(" +32453more")));
|
|
369
|
-
try std.testing.expectEqual(std.math.maxInt(c_longlong), atoll(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_longlong)}))));
|
|
370
|
-
try std.testing.expectEqual(std.math.minInt(c_longlong), atoll(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_longlong)}))));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// FIXME: We cannot test strtol, strtoll, strtoul, etc.. here as it must modify errno and libc is not linked in tests
|
|
374
|
-
|
|
375
|
-
test bsearch {
|
|
376
|
-
const Comparison = struct {
|
|
377
|
-
pub fn compare(a: *const anyopaque, b: *const anyopaque) callconv(.c) c_int {
|
|
378
|
-
const a_u16: *const u16 = @ptrCast(@alignCast(a));
|
|
379
|
-
const b_u16: *const u16 = @ptrCast(@alignCast(b));
|
|
380
|
-
|
|
381
|
-
return switch (std.math.order(a_u16.*, b_u16.*)) {
|
|
382
|
-
.gt => 1,
|
|
383
|
-
.eq => 0,
|
|
384
|
-
.lt => -1,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
const items: []const u16 = &.{ 0, 5, 7, 9, 10, 200, 512, 768 };
|
|
390
|
-
|
|
391
|
-
try std.testing.expectEqual(@as(?*anyopaque, null), bsearch(&@as(u16, 2000), items.ptr, items.len, @sizeOf(u16), Comparison.compare));
|
|
392
|
-
|
|
393
|
-
for (items) |*value| {
|
|
394
|
-
try std.testing.expectEqual(@as(*const anyopaque, value), bsearch(value, items.ptr, items.len, @sizeOf(u16), Comparison.compare));
|
|
395
|
-
}
|
|
396
|
-
}
|