aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
AgeCommit message (Collapse)Author
2022-04-05zig fmt: remove trailing whitespace on doc commentsDamien Firmenich
Fixes #11353 The renderer treats comments and doc comments differently since doc comments are parsed into the Ast. This commit adds a check after getting the text for the doc comment and trims whitespace at the end before rendering. The `a = 0,` in the test is here to avoid a ParseError while parsing the test.
2022-03-30replace other uses of `std.meta.Vector` with `@Vector` (#11346)Meghan
2022-03-12std.math.lossyCast: fix integer overflowominitay
Fixes integer overflow caused by cast from maxInt(u32) as an f32 to u32.
2022-03-11std.math: remove redundant namespace in test namesAndrew Kelley
related: #7923
2022-02-23stage2: misc fixes in SemaVeikka Tuominen
2022-02-13Simplify implementation of floorPowerOfTwo in std.mathCody Tapscott
2022-02-12make f80 less hacky; lower as u80 on non-x86Andrew Kelley
Get rid of `std.math.F80Repr`. Instead of trying to match the memory layout of f80, we treat it as a value, same as the other floating point types. The functions `make_f80` and `break_f80` are introduced to compose an f80 value out of its parts, and the inverse operation. stage2 LLVM backend: fix pointer to zero length array tripping LLVM assertion. It now checks for when the element type is a zero-bit type and lowers such thing the same way that pointers to other zero-bit types are lowered. Both stage1 and stage2 LLVM backends are adjusted so that f80 is lowered as x86_fp80 on x86_64 and i386 architectures, and identical to a u80 on others. LLVM constants are lowered in a less hacky way now that #10860 is fixed, by using the expression `(exp << 64) | fraction` using llvm constants. Sema is improved to handle c_longdouble by recursively handling it correctly for whatever the float bit width is. In both stage1 and stage2.
2022-02-12stage1: fix f80 size and alignment on x86 and armAndrew Kelley
* F80Repr extern struct needs no explicit padding; let's match the target padding. * stage2: fix lowering of f80 constants. * stage1: decide ABI size and alignment of f80 based on alignment of u64. x86 has alignof u64 equal to 4 but arm has it as 8. * stage2: fix Value.floatReadFromMemory to use F80Repr
2022-02-04stage1: make f80 always size 16, align 16Veikka Tuominen
2022-02-04compiler-rt: add extend functions for f80Veikka Tuominen
2022-01-28std: add f80 bitsVeikka Tuominen
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-23std/math: add ldexp and make scalbn an aliasMarc Tiehuis
We assume we are compiled on a base-2 radix floating point system. This is a reasonable assumption. musl libc as an example also assumes this. We implement scalbn as an alias for ldexp, since ldexp is defined as 2 regardless of the float radix. This is opposite to musl which defines scalbn in terms of ldexp. Closes #9799.
2021-10-05add support for f128 `@mulAdd`Andrew Kelley
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-04add phi constantalichraghi
2021-10-02Document some functions in std.math.Nathan Michaels
2021-09-14add functions to decode an epoch timestamp (#9040)Jonathan Marler
* add functions to decode an epoch timestamp The code added here is alternative to the libc gmtime function. This function takes a unix epoch timestamp and decodes it into things like the year/day/time/etc. I looked at various libc implementations to see how it was implemented and this appears to be correct. I reorganized it so that applications can choose which data they need rather than calcualting it all in a single function. The data structures layout the order of operations required to decode various things like the year/month or time of day. * set Month.jan to 1 instead of 0 to avoid +1 in conversion to numeric * add another test * remove unnecessary comptimeMod
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
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-23Trivial typo "for for" --> "for" (also a few nearby run-on sentence). (#9610)William Stein
2021-06-10zig fmtAndrew Kelley
2021-06-03Breaking hash map changes for 0.8.0Martin Wickham
- hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig
2021-05-20Run `zig fmt` on src/ and lib/std/Isaac Freund
This replaces callconv(.Inline) with the more idiomatic inline keyword.
2021-05-08Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
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-08std: update usage of std.testingVeikka Tuominen
2021-04-24Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
In particular I wanted the change that makes `suspend;` illegal in the parser.
2021-04-23std: Remove unneeded workaroundLemonBoy
Now that -% works on unsigned integers at comptime this (clever) hack is not not needed anymore.
2021-04-22std: remove `comptime const`Andrew Kelley
2021-03-01zig fmt the std libAndrew Kelley
2021-03-01Add some bit set variantsMartin Wickham
2021-01-25Merge pull request #7846 from LemonBoy/filtertestAndrew Kelley
stage1: don't filter test blocks with empty label
2021-01-22std: Update `test ""` to `test` where it makes senseLemonBoy
2021-01-19stage2: ELF: avoid multiplication for ideal capacityAndrew Kelley
ideal capacity is now determined by e.g. x += x / f rather than x = x * b / a This turns a multiplication into an addition, making it less likely to overflow the integer. This commit also introduces padToIdeal() which does saturating arithmetic so that no overflow is possible when calculating ideal capacity. closes #7830
2021-01-10zig fmtAndrew Kelley
2021-01-10impl lossyCast #5080Adam Goertz
2020-12-31Year++Frank Denis
2020-12-16Fix typo in math.orderdata-man
2020-11-19Add builtin.Signedness, use it instead of is_signedTadeo Kondrak
2020-11-06Merge pull request #6941 from LemonBoy/floateqapproxAndrew Kelley
std: Implement more useful approxEq semantics
2020-11-05math.shl/math.shr: add support for vectorsFrank Denis
2020-11-05std: Implement more useful approxEq semanticsLemonBoy
Comparisons with absolute epsilons are usually useful when comparing numbers to zero, for non-zero numbers it's advised to switch to relative epsilons instead to obtain meaningful results (check [1] for more details). The new API introduces approxEqAbs and approxEqRel, where the former aliases and deprecated the old `approxEq`, allowing the user to pick the right tool for the job. The documentation is meant to guide the user in the choice of the correct alternative. [1] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
2020-10-29std/math: add support for vectors to rotl()/rotr()Frank Denis
2020-10-17Make std.meta.Int accept a signedness parameterJan Prudil
2020-10-15std: move std.meta.refAllDecls to std.testingTadeo Kondrak
2020-10-07restore ability to do comptime mathxavier
until https://github.com/ziglang/zig/issues/6168 is implemented, partially revert 0bd53dd2033c60d3446abfb83209237c6eb6c9e2 in order to restore the ability to use std.math in comptime functions.
2020-09-03update uses of deprecated type field accessVexu
2020-08-30Merge pull request #6189 from katesuyu/div-ceilAndrew Kelley
std: Add std.math.divCeil
2020-08-29std.math.divCeil: fix expectEqual argument orderKate Tsuyu
2020-08-29std.math.divCeil: use expectEqual for testsKate Tsuyu
2020-08-29std.math.divCeil: move compile error back downKate Tsuyu
2020-08-29std.math.divCeil: move compile error to topKate Tsuyu