Commit graph

377 commits

Author SHA1 Message Date
Miles Alan
411e9ca4ad
Fix bug where std.math.asinh64 doesn't respect signedness for negative values (#9940)
* std: Correct math.asinh64 to return correct signedness for negative values

* std: Add tests for negative values for math.asinh32 and math.asinh64
2021-10-15 13:55:40 -04:00
Andrew Kelley
5518a0aff2 freestanding libc: export fmal
libc requires this to use `long double` which is sometimes the same as
f128, sometimes not.

Also for an unknown reason, aarch64 is getting an invalid result for the
`@mulAdd` behavior test for f128. See #9900.
2021-10-05 16:56:46 -07:00
Andrew Kelley
2fe7b06f3d add support for f128 @mulAdd
std: add f128 implementations of fma, frexp, and ilogb. Expose `fmal` in
zig's freestanding libc. This makes `@mulAdd` work correctly for f128.

Fixes a CI regression from yesterday, where I added a usage of f128
`@mulAdd` into the self-hosted compiler.
2021-10-05 12:32:26 -07:00
Andrew Kelley
78902db68b stage2: fix comptime @bitCast
Before, Sema for comptime `@bitCast` would return the same Value but
change the Type. This gave invalid results because, for example, an
integer Value when the Type is a float would be interpreted numerically,
but `@bitCast` needs it to reinterpret how they would be stored in
memory.

This requires a mechanism to serialize a Value to a byte buffer and
deserialize a Value from a byte buffer.

Not done yet, but needs to happen: comptime dereferencing a pointer
to a Decl needs to perform a comptime bitcast on the loaded value.
Currently the value is silently wrong in the same way that `@bitCast`
was silently wrong before this commit.

The logic in Value for handling readFromMemory for large integers is
only correct for small integers. It needs to be fleshed out for proper
big integers.

As part of this change:
 * std.math.big.Int: initial implementations of readTwosComplement and
   writeTwosComplement. They only support bit_count <= 128 so far and
   panic otherwise.
 * compiler-rt: move the compareXf2 exports over to the stage2 section.
   Even with the improvements in this commit, I'm still seeing test
   failures in the widening behavior tests; more investigation is
   needed.
2021-10-04 23:30:04 -07:00
Robin Voetter
95fe86e3db big ints: Fix tests for 32-bit architectures 2021-10-04 11:25:29 +02:00
Robin Voetter
a1e02f33ad fmt 2021-10-04 11:25:29 +02:00
Robin Voetter
3dc47b8161 Apply new big int wrap/saturate to Value.zig 2021-10-04 11:25:29 +02:00
Robin Voetter
a62ce87f1f big ints: mulWrap tests 2021-10-04 11:25:29 +02:00
Robin Voetter
b352564b36 big ints: Some extra comments 2021-10-04 11:25:29 +02:00
Robin Voetter
ebcdfebaa6 big ints: saturate() tests 2021-10-04 11:25:29 +02:00
Robin Voetter
bbd50248f2 big ints: saturate() function 2021-10-04 11:25:29 +02:00
Robin Voetter
fdf13fb819 big ints: Wrapping multiplication 2021-10-04 11:25:29 +02:00
Robin Voetter
41e9c1bac1 big ints: Allow llmulaccum to wrap 2021-10-04 11:25:29 +02:00
Robin Voetter
5907b3e383 big ints: Improve karatsuba multiplication 2021-10-04 11:25:29 +02:00
Robin Voetter
15351f206f big.int: truncate tests 2021-10-04 11:25:29 +02:00
Robin Voetter
692827baa7 big ints: [add|sub]Sat tests 2021-10-04 11:25:29 +02:00
Robin Voetter
52721d3a7e big ints: [add|sub]Wrap tests 2021-10-04 11:25:29 +02:00
Robin Voetter
bb53f4f15a big ints: implement normal/wrapping/saturating subtraction in terms of addition 2021-10-04 11:25:29 +02:00
Robin Voetter
16991f920b big ints: saturating addition 2021-10-04 11:25:29 +02:00
Robin Voetter
f1b3a90ef6 big ints: setTwosCompIntLimit
This function can be used to initialize a big integer to either the upper
or lower limit of a 2s-complement integer. Note that the result is still
in sign-magnitude representation, though in order to convert it into twos
complement all one has to do is take the absolute value.
2021-10-04 11:25:29 +02:00
Robin Voetter
dc1f698545 big ints: unify add/sub with their wrapping variants 2021-10-04 11:25:29 +02:00
Robin Voetter
a36ef84deb big ints: Basic wrapping multiplication 2021-10-04 11:25:29 +02:00
Robin Voetter
69be6ba8ee Comptime wrapping addition/subtraction 2021-10-04 11:25:29 +02:00
Robin Voetter
fdb37743fa big ints: addWrap, subWrap + fix Managed.truncate allocation size 2021-10-04 11:25:29 +02:00
Robin Voetter
b58cf6dab6 big ints: 2s complement truncate 2021-10-04 11:25:29 +02:00
Robin Voetter
616b23c815 big ints: split lladd/llsub into carry variants
lladd is now implemented in terms of lladdcarry, which returns the carry limb.
Similarly, llsub is implemented using llsubcarry, which returns the borrow limb.
2021-10-04 11:25:29 +02:00
Robin Voetter
cd3dcc225b big ints: only write xor overflow if required 2021-09-23 06:28:09 +02:00
Robin Voetter
351e4f07ce big ints: 2s complement signed and + or fixes 2021-09-23 06:19:08 +02:00
Robin Voetter
f5c27dd11a big ints: 2s complement signed or 2021-09-23 04:08:27 +02:00
Robin Voetter
4afe4bdfe7 big ints: 2s complement signed xor 2021-09-22 02:21:55 -04:00
Andrew Kelley
4b2d7a9c67 stage2: implement comptime bitwise nand 2021-09-20 15:44:09 -07:00
Andrew Kelley
c05a20fc8c std: reorganization that allows new usingnamespace semantics
The proposal #9629 is now accepted, usingnamespace stays but no longer
puts identifiers in scope.
2021-09-01 17:54:06 -07:00
Andrew Kelley
d29871977f remove redundant license headers from zig standard library
We already have a LICENSE file that covers the Zig Standard Library. We
no longer need to remind everyone that the license is MIT in every single
file.

Previously this was introduced to clarify the situation for a fork of
Zig that made Zig's LICENSE file harder to find, and replaced it with
their own license that required annual payments to their company.
However that fork now appears to be dead. So there is no need to
reinforce the copyright notice in every single file.
2021-08-24 12:25:09 -07:00
Adam C
95e5fac412
FIX typo in doc comment for std.math.hypot (#9413) 2021-07-18 23:53:06 +02:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Jacob G-W
641ecc260f std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
LemonBoy
44cdafd9d4 std: Fix complex ldexp implementation
Two bugs in the implementation ported from musl made all the complex
functions relying on ldexp return incorrect results in some cases.

Spotted in #9047
2021-06-12 19:56:08 +03:00
Asherah Connor
e56ba4cee1 bigint: add ensureAdd(Scalar)Capacity, note aliasing requirements 2021-06-11 16:18:10 +03:00
Asherah Connor
b15e205438 bigint: use a stack local here to prevent aliasing issues 2021-06-11 16:18:10 +03:00
Asherah Connor
1db6018140 bigint: add failing tests for bigint carry 2021-06-11 16:18:06 +03:00
LemonBoy
56c0a66ce3 std: Fix tanh for negative inputs
It turns out the code was not ported correctly from C and produced wrong
results for negative input values. As a bonus fix the NaN codepath by
adding yet another missing piece of code.

Spotted in #9047
2021-06-11 14:04:46 +03:00
daurnimator
916b645fc1 Have std.fmt functions take case as an enum 2021-06-10 08:33:42 +03:00
Filippo Casarin
8b0dbca32d std.math.sqrt_int: fixed odd size integers types 2021-06-09 19:16:55 +03:00
Isaac Freund
5b850d5c92
Run zig fmt on src/ and lib/std/
This replaces callconv(.Inline) with the more idiomatic inline keyword.
2021-05-20 17:14:18 +02:00
Andrew Kelley
615d45da77 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * src/codegen/spirv.zig
 * src/link/SpirV.zig

We're going to want to improve the stage2 test harness to print
the source file name when a compile error occurs otherwise std lib
contributors are going to see some confusing CI failures when they cause
stage2 AstGen compile errors.
2021-05-17 19:30:38 -07:00
aiz
5414bd48ed
std.math.Complex: Change new() to init() 2021-05-17 21:57:51 +02:00
Andrew Kelley
597082adf4 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
2021-05-15 21:44:38 -07:00
viri
612ad779bb
std: rework math.scalbn (#8733)
* std: fix overflow in math.scalbn32

* std: rewrite math.scalbn to be generic

* std: support f128 in math.isNormal

* std: enable f128 tests in math.scalbn
2021-05-14 16:15:53 -04:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00