aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
AgeCommit message (Collapse)Author
2025-08-30std: skip some failing tests on hexagonAlex Rønne Petersen
2025-08-15std.math: Add splat for vectors of u0s in rotl/rotr (#24822)Fri3dNstuff
2025-07-31std: stop relying on precision-losing coercionsmlugg
2025-07-22aarch64: add new from scratch self-hosted backendJacob Young
2025-06-15big.int: implement float conversionsJacob Young
These conversion routines accept a `round` argument to control how the result is rounded and return whether the result is exact. Most callers wanted this functionality and had hacks around it being missing. Also delete `std.math.big.rational` because it was only being used for float conversion, and using rationals for that is a lot more complex than necessary. It also required an allocator, whereas the new integer routines only need to be passed enough memory to store the result.
2025-06-05std.Target: Introduce Cpu convenience functions for feature tests.Alex Rønne Petersen
Before: * std.Target.arm.featureSetHas(target.cpu.features, .has_v7) * std.Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }) * std.Target.wasm.featureSetHasAll(target.cpu.features, .{ .atomics, .bulk_memory }) After: * target.cpu.has(.arm, .has_v7) * target.cpu.hasAny(.x86, &.{ .sse, .avx, .cmov }) * target.cpu.hasAll(.wasm, &.{ .atomics, .bulk_memory })
2025-05-17x86_64: rewrite scalar `<<|`Jacob Young
Closes #23035
2025-04-13std: eradicate u29 and embrace std.mem.AlignmentAndrew Kelley
2025-03-24std.math: Add least common multiple (lcm)oittaa
2025-02-12std: remove special cases for stage2_x86_64 that are no longer neededJacob Young
2024-09-02std.math: rename make_f80 to F80.toFloat and break_f80 to F80.fromFloatJeremy Hertel
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
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-21std: update eval branch quotas after bdbc485mlugg
Also, update `std.math.Log2Int[Ceil]` to more efficient implementations that don't use up so much damn quota!
2024-08-14langref: clarify functionality of the round builtin (#19503)T
A test has also been added to demonstrate the expected behavior. * std.math: update round doc comment to match the builtin
2024-07-25aarch64: reenable tests that are no longer regressedJulian Vesper
Closes #12012
2024-06-01Support Vectors in std.math.clampkoenditor
2024-05-30std/math: import "math/float.zig" only onceManlio Perillo
math.zig imported the "math/float.zig" file multiple time, making the code unnecessarily more verbose.
2024-05-30math.hypot: fix incorrect over/underflow behavior (#19472)expikr
2024-05-03Delete compile errors for deprecated declsRyan Liptak
2024-04-14WindowsSdk: fix for new x86_64-windows CIJacob Young
2024-03-29std.math: rework modfSean
- 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-21std: promote tests to doctestsAndrew Kelley
Now these show up as "example usage" in generated documentation.
2024-03-15make `math.degreesToRadians` and `math.radiansToDegrees` infer type from ↵expikr
argument
2024-03-15fix(math): eval isPowerOfTwo at comptime in rotl/rotrpaoda
2024-03-13remove `math.lerp` bounds for tpancelor
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-02-26Remove redundant test name prefixes now that test names are fully qualifiedRyan Liptak
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-01-14std.math: add `wrap` function (#18154)expikr
2024-01-13fix #17142, wrong comptime log_int computationGuillaume Wenzek
2024-01-09Add std.math.gamma and lgamma (#18449)PauloCampana
See #7212
2024-01-07Add approxEqAbs support for comptime_floatEric Eastwood
2024-01-03Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"Jacob Young
This reverts commit 2b589783602c5428ecde9dbb3f41a81f85eb0f25.
2024-01-01Revert "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"Andrew Kelley
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-01Merge pull request #17824 from kcbanner/fixup_msvc_fmaxAndrew Kelley
cbe: add a system for avoiding collisions with C compiler intrinsics
2023-11-23Deprecate math.doNotOptimizeAway, use mem.doNotOptimizeAway (#18011)John Benediktsson
2023-11-22std: remove meta.traitAndrew Kelley
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-19lib: correct unnecessary uses of 'var'mlugg
2023-11-09std.math: Add isPositiveZero() and isNegativeZero()Linus Groh
2023-11-05cbe: skip std.math.lerp test that fails when compiler_rt fma is usedkcbanner
2023-11-03x86_64: fix std test failuresJacob Young
2023-10-23x86_64: implement `@mod` for floating-point typesJacob Young
2023-10-22Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""Jacob Young
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"Andrew Kelley
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-22Merge pull request #17637 from jacobly0/x86_64-test-stdJacob Young
x86_64: start to enable `test-std` and `test-compiler-rt` testing
2023-10-21Return zero for NaN-to-int lossy castsMichael Bradshaw
Fixes #15038. The goal here is to guarantee lossyCast() is panic-free and always safe.
2023-10-21x86_64: fix bugs and disable erroring testsJacob Young
2023-10-06std.math: add nextAfter (#16894)castholm
`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-09-27Remove `@fabs`, fabs and absCast/Int from std libantlilja
Replaces occurences of @fabs absCast and absInt with new @abs builtin. Also removes the std.math.fabs alias from math.zig.
2023-09-18std: math.absInt: update docs to use fabs for floatsMeghan Denny
2023-09-14std.math.log_int: implement integer logarithm without using float mathFederico Stra
2023-08-18Make NaNs quiet by default and other NaN tidy-up (#16826)Lewis Gaul
* 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