aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math
AgeCommit message (Collapse)Author
2022-09-04Fix #12440: std.math.big.Rational order/orderAbsYujiri
2022-08-24Merge pull request #12574 from Vexu/remove-bit-op-type-paramAndrew Kelley
stage2+stage1: remove type parameter from bit builtins
2022-08-22stage2+stage1: remove type parameter from bit builtinsVeikka Tuominen
Closes #12529 Closes #12511 Closes #6835
2022-08-22Sema: fix parameter of type 'T' must be comptime errorVeikka Tuominen
Closes #12519 Closes #12505
2022-07-16Use Managed.len in sub, divFloor, and divTrunc tooHiroaki Nakamura
2022-07-16Use Managed.len() instead of Managed.toConst().limbs.lenHiroaki Nakamura
2022-07-16Fix std.math.big.int.Managed capacity after mul and sqrHiroaki Nakamura
2022-07-13stage2: fix comptime bitcast involving f80Andrew Kelley
* Sema: implement comptime bitcast of f80 with integer-like types bitwise rather than taking a round trip through memory layout. * Type: introduce `isAbiInt`. * Value: comptime memory write of f80 writes 0 bytes for padding instead of leaving the memory uninitialized. * Value: floatReadFromMemory has a more general implementation, checking the endianness rather than checking for specific architectures. This fixes behavior test failures occurring on MIPS.
2022-07-13std.math: add `inline` to some functionsAndrew Kelley
These functions semantically benefit from being inline; it makes sense that `isInf(x)` where `x` is comptime-known should have a comptime-known result.
2022-06-30stage2: lower float negation explicitlyAndrew Kelley
Rather than lowering float negation as `0.0 - x`. * Add AIR instruction for float negation. * Add compiler-rt functions for f128, f80 negation closes #11853
2022-06-29std.math.big.int: breaking API changes to prevent UAFAndrew Kelley
Many of the Managed methods accepted by-val parameters which could reference Limb slices that became invalid memory after any ensureCapacity calls. Now, Managed methods accept `*const Managed` parameters so that if the function allows aliasing and the ensure-capacity call resizes the Limb slice, it also affects the aliased parameters, avoiding use-after-free bugs. This is a breaking change that reduces the requirement for callsites to manually make the ensure-capacity changes prior to calling many of the Managed methods. Closes #11897
2022-06-13std.math.big.int: update Managed.toString() to use provided allocator (#11839)Mikael Berthe
2022-06-12std: disable failing tests, add zig2 build test-std to CIVeikka Tuominen
2022-06-07std.math: Add O(log N) implementation of log2(x) for comptime_intCody Tapscott
Since Zig provides @clz and not @ffs (find-first-set), log2 for comptime integers needs to be computed algorithmically. To avoid hitting the backward branch quota, this updates log2(x) to use a simple O(log N) algorithm.
2022-06-07std: adjust for stage2 semanticsVeikka Tuominen
2022-06-01Sema: apply previous changes to `validateUnionInit`Veikka Tuominen
2022-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-05-17std.math: simpler error handlingalice
2022-05-17Simplify `Copysign`alice
2022-05-17Simplify `signbit`alice
2022-05-16`std.math.powi`: use standard definition of underflow/overflow, implement ↵leesongun
`u0`, `i0`, `i1` edge case (#11499)
2022-04-27std: use float builtins instead of std.mathAndrew Kelley
2022-04-27add new builtin function `@tan`Andrew Kelley
The reason for having `@tan` is that we already have `@sin` and `@cos` because some targets have machine code instructions for them, but in the case that the implementation needs to go into compiler-rt, sin, cos, and tan all share a common dependency which includes a table of data. To avoid duplicating this table of data, we promote tan to become a builtin alongside sin and cos. ZIR: The tag enum is at capacity so this commit moves `field_call_bind_named` to be `extended`. I measured this as one of the least used tags in the zig codebase. Fix libc math suffix for `f32` being wrong in both stage1 and stage2. stage1: add missing libc prefix for float functions.
2022-04-27stage2: fix recent LLVM backend codeAndrew Kelley
* std.math.snan: fix compilation error. Also make it and nan inline. * LLVM: use a proper enum type for float op instead of enum literal. Also various cleanups. * LLVM: use LLVMBuildVectorSplat for vector splat AIR instruction. - also the bindings had parameter order wrong * LLVM: additionally handle f16 lowering. For now all targets report OK but I think we will need to add some exceptions to this list.
2022-04-27compiler-rt: math functions reorgAndrew Kelley
* unify the logic for exporting math functions from compiler-rt, with the appropriate suffixes and prefixes. - add all missing f128 and f80 exports. Functions with missing implementations call other functions and have TODO comments. - also add f16 functions * move math functions from freestanding libc to compiler-rt (#7265) * enable all the f128 and f80 code in the stage2 compiler and behavior tests (#11161). * update std lib to use builtins rather than `std.math`.
2022-04-25stdlib: Fix hex-float printing for f80Cody Tapscott
2022-04-15std.math.fabs: enable f80 testingvi
2022-04-15std.math: enable f80 tests on freebsdvi
2022-04-15std: add workaround for stage2 bugVeikka Tuominen
2022-04-14std.math.float: fix f80-backed c_longdouble constsvi
2022-04-12Add `floatFractionalBits` to replace `floatMantissaDigits`Cody Tapscott
2022-04-08std.math.isInf: add tests for +-NaNviri
2022-04-07use math/float.zig everywhereviri
2022-04-07std.math.is*Inf: make generic, support f80viri
2022-04-07std.math: generalise `inf`, even simpler `isFinite`viri
2022-04-07std.math.isFinite: make generic, support f80viri
2022-04-06std.{fmt, math}: derive float constants from stdviri
This also addresses a nit from #10133 where IntT might be a confusing name because it might imply signed integer (iX, not uX). We settled on TBits for math/float.zig so I've applied that change here too. When I originally wrote ldexp() I copied the name from parse_hex_float.
2022-04-06math.fabs: simplify implementation, add testsviri
2022-04-06math.isNormal: simplify implementation, add testsviri
2022-04-06derive float constants in a generic way (#10133)viri
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-27std.math.Complex: add 'negation' and 'mulitply by i'BlueAlmost
2022-03-23math/big: correct fix for divmod (#11271)Marc Tiehuis
Fixes #11166.
2022-03-14freestanding libc: include roundlAndrew Kelley
2022-03-10math: fix big.int div, gcd and bitAnd edge-casesMarc Tiehuis
Fixes #10932.
2022-03-06stage2: rework `@mulAdd`Andrew Kelley
* mul_add AIR instruction: use `pl_op` instead of `ty_pl`. The type is always the same as the operand; no need to waste bytes redundantly storing the type. * AstGen: use coerced_ty for all the operands except for one which we use to communicate the type. * Sema: use the correct source location for requireRuntimeBlock in handling of `@mulAdd`. * native backends: handle liveness even for the functions that are TODO. * C backend: implement `@mulAdd`. It lowers to libc calls. * LLVM backend: make `@mulAdd` handle all float types. - improved fptrunc and fpext to handle f80 with compiler-rt calls. * Value.mulAdd: handle all float types and use the `@mulAdd` builtin. * behavior tests: revert the changes to testing `@mulAdd`. These changes broke the test coverage, making it only tested at compile-time. Improved f80 support: * std.math.fma handles f80 * move fma functions from freestanding libc to compiler-rt - add __fmax and fmal - make __fmax and fmaq only exported when they don't alias fmal. - make their linkage weak just like the rest of compiler-rt symbols. * removed `longDoubleIsF128` and replaced it with `longDoubleIs` which takes a type as a parameter. The implementation is now more accurate and handles more targets. Similarly, in stage2 the function CTypes.sizeInBits is more accurate for long double for more targets.
2022-02-18stage2: Implement `@bitReverse` and `@byteSwap`Cody Tapscott
This change implements the above built-ins for Sema and the LLVM backend. Other backends have had placeholders added for lowering.
2022-02-18Merge pull request #10858 from topolarity/stage2-bitcastAndrew Kelley
stage2 sema: Fix sign handling of exotic integers in `@bitCast`
2022-02-17Replace magic numbers with clearer representationJ87
Replaces two magic numbers with the procedure used to generate them, in order to keep consistent with other implementations for f64 & f128.
2022-02-13Add additional tests for `@bitCast`Cody Tapscott