176 Commits

Author SHA1 Message Date
Jeremy Hertel
227fb4875f std.math: rename make_f80 to F80.toFloat and break_f80 to F80.fromFloat 2024-09-02 00:10:22 +03:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
mlugg
018262d537
std: update eval branch quotas after bdbc485
Also, update `std.math.Log2Int[Ceil]` to more efficient implementations
that don't use up so much damn quota!
2024-08-21 01:30:46 +01:00
T
eb7f318ea8
langref: clarify functionality of the round builtin (#19503)
A test has also been added to demonstrate the expected behavior.

* std.math: update round doc comment to match the builtin
2024-08-14 10:29:45 -07:00
Julian Vesper
3344ed8b8f aarch64: reenable tests that are no longer regressed
Closes #12012
2024-07-25 20:23:23 +03:00
koenditor
64ef45eb05 Support Vectors in std.math.clamp 2024-06-01 13:28:16 +03:00
Manlio Perillo
e54fcdb5b2 std/math: import "math/float.zig" only once
math.zig imported the "math/float.zig" file multiple time, making the
code unnecessarily more verbose.
2024-05-30 19:57:24 +03:00
expikr
103b885fc6
math.hypot: fix incorrect over/underflow behavior (#19472) 2024-05-30 09:58:05 +00:00
Ryan Liptak
a52f12afc9 Delete compile errors for deprecated decls 2024-05-03 13:27:30 -07:00
Jacob Young
425e38b6e0 WindowsSdk: fix for new x86_64-windows CI 2024-04-14 21:26:08 -04:00
Sean
a2df84d0ff
std.math: rework modf
- Changed `modf_result` to `Modf` to better fit naming conventions
- Reworked `modf` to be far simpler and support all floating point types (as well as vectors) (I have done benchmarks and can confirm that the performance is roughly equivalent to the old implementation)
- Added more descriptive tests for modf
- Deprecated `modf32_result` and `modf64_result` in favor of `Modf(f32)` and `Modf(f64)` respectively
2024-03-29 09:33:57 +00:00
Andrew Kelley
12191c8a22 std: promote tests to doctests
Now these show up as "example usage" in generated documentation.
2024-03-21 14:11:46 -07:00
expikr
67a40c679d
make math.degreesToRadians and math.radiansToDegrees infer type from argument 2024-03-15 16:31:02 +02:00
paoda
a4508ad716 fix(math): eval isPowerOfTwo at comptime in rotl/rotr 2024-03-15 16:19:48 +02:00
pancelor
7a858257f2 remove math.lerp bounds for t
I think of lerp() as a way to change coordinate systems, essentially
remapping the input numberline onto a shifted+rescaled numberline. In
my mind the full numberline is remapped, not just the 0-1 segment.

An example of how this is useful: in a game, you can write:
`myPos = lerp(pos0, pos1, easeOutBack(u))`
for some `u` that changes from 0 to 1 over time.
(see https://easings.net/#easeOutBack)
This will animate `myPos` between `pos0` and `pos1`, overshooting the
goal position `pos1` in a nicely-animated way.
`easeOutBack(float)->float` is a pure function that overshoots 1,
and by combining it with `lerp()` we can remap coordinates in other
coordinate systems, making them overshoot in the same way.

However, this overshooting is only possible because `easeOutBack(t)`
sometimes exceeds the range 0-1 (e.g. `easeOutBack(0.5)` is 1.0877),
which is not allowed by the current `math.lerp` implementation.

This commit removes the asserts that prevented this use-case. Now, any
value can be inputted for t. For example, `lerp(10,20, 2.0)` will now
return 30, instead of throwing an assert error.
2024-03-13 18:35:07 -07:00
Ryan Liptak
16b3d1004e Remove redundant test name prefixes now that test names are fully qualified
Follow up to #19079, which made test names fully qualified.

This fixes tests that now-redundant information in their test names. For example here's a fully qualified test name before the changes in this commit:

"priority_queue.test.std.PriorityQueue: shrinkAndFree"

and the same test's name after the changes in this commit:

"priority_queue.test.shrinkAndFree"
2024-02-26 15:18:31 -08:00
expikr
1a7a711964
std.math: add wrap function (#18154) 2024-01-14 20:45:39 -05:00
Guillaume Wenzek
c5d359e4cd fix #17142, wrong comptime log_int computation 2024-01-13 18:46:16 -08:00
PauloCampana
fcc0c5ddc7
Add std.math.gamma and lgamma (#18449)
See #7212
2024-01-09 14:53:47 -08:00
Eric Eastwood
2115d7d1be Add approxEqAbs support for comptime_float 2024-01-07 22:23:06 -08:00
Jacob Young
98b633ff17 Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 2b589783602c5428ecde9dbb3f41a81f85eb0f25.
2024-01-03 02:41:21 -05:00
Andrew Kelley
2b58978360 Revert "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 7161ed79c4abcaccdd56fe0b4fbd3d93472d41b8, reversing
changes made to 3f2a65594e1d3c0a4f4943a4ea522e8405db81e0.

Unfortunately, this sat in the PR queue too long and the merge broke the
zig1.wasm bootstrap process.
2024-01-01 17:49:57 -07:00
Andrew Kelley
7161ed79c4
Merge pull request #17824 from kcbanner/fixup_msvc_fmax
cbe: add a system for avoiding collisions with C compiler intrinsics
2024-01-01 15:36:16 -08:00
John Benediktsson
54f4abae2f
Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011) 2023-11-23 15:06:32 -05:00
Andrew Kelley
d5e21a4f1a std: remove meta.trait
In general, I don't like the idea of std.meta.trait, and so I am
providing some guidance by deleting the entire namespace from the
standard library and compiler codebase.

My main criticism is that it's overcomplicated machinery that bloats
compile times and is ultimately unnecessary given the existence of Zig's
strong type system and reference traces.

Users who want this can create a third party package that provides this
functionality.

closes #18051
2023-11-22 13:24:27 -05:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
Linus Groh
e72049bc61 std.math: Add isPositiveZero() and isNegativeZero() 2023-11-09 00:55:43 -07:00
kcbanner
8c0e0cd353 cbe: skip std.math.lerp test that fails when compiler_rt fma is used 2023-11-05 20:34:16 -05:00
Jacob Young
509be7cf1f x86_64: fix std test failures 2023-11-03 23:18:21 -04:00
Jacob Young
fbe8c8938b x86_64: implement @mod for floating-point types 2023-10-23 22:42:18 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing
changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
0c99ba1eab
Merge pull request #17637 from jacobly0/x86_64-test-std
x86_64: start to enable `test-std` and `test-compiler-rt` testing
2023-10-22 08:06:47 -04:00
Michael Bradshaw
cc56577edf Return zero for NaN-to-int lossy casts
Fixes #15038.

The goal here is to guarantee lossyCast() is panic-free and always safe.
2023-10-21 20:51:51 +03:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
castholm
ad6f8e3a59
std.math: add nextAfter (#16894)
`nextAfter()` returns the next representable value after `x` in the direction of `y` and is a standard math library function ([C++](https://en.cppreference.com/w/cpp/numeric/math/nextafter), [Java](https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#nextAfter-double-double-)). It is primarily useful for bitwise incrementing/decrementing floats.

This implementation supports runtime integers, runtime floats and `comptime_int`. `comptime_float` is not supported because NaNs/infinities are intentionally difficult to obtain and because I'm not sure if the fact that it's backed by `f128` is supposed to be an implementation detail. Either way, the user could just call the function with the floating-point type whose behavior they want at comptime and then cast the result to `comptime_float`.

The float implementation was ported from mingw-w64 with some slight changes made possible because the Zig standard library doesn't care about raising FP exceptions.

The number of test cases may seem excessive but they should cover every normal and edge case for every float type and are especially important for verifying that `f80` works.
2023-10-06 14:44:47 -04:00
antlilja
bcf4a13913 Remove @fabs, fabs and absCast/Int from std lib
Replaces occurences of @fabs absCast and absInt with new @abs builtin.
Also removes the std.math.fabs alias from math.zig.
2023-09-27 11:24:28 -07:00
Meghan Denny
5af5d87ad2 std: math.absInt: update docs to use fabs for floats 2023-09-18 21:44:56 +03:00
Federico Stra
4f952c7e0e
std.math.log_int: implement integer logarithm without using float math 2023-09-14 19:33:56 +00:00
Lewis Gaul
387b0ac4f1
Make NaNs quiet by default and other NaN tidy-up (#16826)
* Generalise NaN handling and make std.math.nan() give quiet NaNs

* Address uses of std.math.qnan_* and std.math.nan_* consts

* Comment out failing test due to issues with signalling NaN

* Fix issue in c_builtins.zig where we need qnan_u32
2023-08-18 02:07:49 -04:00
Adam Goertz
9e19969e09 Remove math.ln in favor of @log 2023-08-02 12:00:14 -07:00
antlilja
b463e429b8 Remove len parameter from splat in standard lib 2023-07-12 15:35:57 -07:00
Niles Salter
27a66191c2
Change math.Order order (#16356)
This speeds up algorithms like binary search
2023-07-09 01:22:52 -04:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
r00ster91
2839e35d1c std.math.isPowerOfTwo: add tests and doc comment and improve assert
The assert is changed from `int != 0` to `int > 0` because negative
integers always return `false`.
Python's `math.log2` does the same and errors for 0 or negative integers.
2023-06-18 10:42:03 -07:00
r00ster91
2593156068 migration: std.math.{min, min3, max, max3} -> @min & @max 2023-06-16 13:44:09 -07:00
Eric Joldasov
d884d7050e
all: replace comptime try with try comptime
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:46:58 +06:00
Eric Joldasov
d04a262a3d
std.math: hard deprecate obsolete constants (soft deprecated in 0.10)
Followup to 5b8ac9821dd25c3e5282130b4d93d6c5b7debb08.
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:45:12 +06:00
Cortex
6e6a61a384
std.io.Writer: add support for non-power-of-two int sizes 2023-05-29 13:01:54 +03:00