61 Commits

Author SHA1 Message Date
LemonBoy
9ac5f98200 std: Remove unneeded workaround
Now that -% works on unsigned integers at comptime this (clever) hack is
not not needed anymore.
2021-04-23 19:19:44 +02:00
Andrew Kelley
a20169a610 zig fmt the std lib 2021-03-01 20:04:28 -07:00
Martin Wickham
7613e51a57 Add some bit set variants 2021-03-01 18:52:15 -08:00
Andrew Kelley
4ca1f4ec2e
Merge pull request #7846 from LemonBoy/filtertest
stage1: don't filter test blocks with empty label
2021-01-25 10:39:11 -08:00
LemonBoy
134f5fd3d6 std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
Andrew Kelley
d5d0619aac stage2: ELF: avoid multiplication for ideal capacity
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-19 13:47:51 -07:00
Andrew Kelley
169810b20f zig fmt 2021-01-10 19:04:10 -07:00
Adam Goertz
0f32de77c9 impl lossyCast #5080 2021-01-10 19:02:41 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
data-man
d877eb0e8d Fix typo in math.order 2020-12-16 12:14:44 +02:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Andrew Kelley
d1b1f053b0
Merge pull request #6941 from LemonBoy/floateqapprox
std: Implement more useful approxEq semantics
2020-11-06 14:09:31 -05:00
Frank Denis
2e354c387e math.shl/math.shr: add support for vectors 2020-11-05 17:20:54 -05:00
LemonBoy
ff14451b4a std: Implement more useful approxEq semantics
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-11-05 16:08:49 +01:00
Frank Denis
bb3dfd2708 std/math: add support for vectors to rotl()/rotr() 2020-10-29 14:17:46 -04:00
Jan Prudil
aadccc4206 Make std.meta.Int accept a signedness parameter 2020-10-17 14:09:59 +02:00
Tadeo Kondrak
e892ee17e6 std: move std.meta.refAllDecls to std.testing 2020-10-15 20:34:22 -04:00
xavier
a0a834a2f2 restore ability to do comptime math
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-10-07 17:04:48 -04:00
Vexu
1df0f3ac24
update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
Andrew Kelley
427e2d689d
Merge pull request #6189 from katesuyu/div-ceil
std: Add std.math.divCeil
2020-08-30 01:09:39 -04:00
Kate Tsuyu
e496485af4
std.math.divCeil: fix expectEqual argument order 2020-08-29 03:07:36 -04:00
Kate Tsuyu
552e2bf758
std.math.divCeil: use expectEqual for tests 2020-08-29 02:32:54 -04:00
Kate Tsuyu
340871f061
std.math.divCeil: move compile error back down 2020-08-29 00:37:10 -04:00
Kate Tsuyu
49e67ce0e8
std.math.divCeil: move compile error to top 2020-08-29 00:31:49 -04:00
Kate Tsuyu
933bfcff64
std.math.divCeil: support comptime_int/float 2020-08-29 00:21:17 -04:00
Kate Tsuyu
f577d12fbc
std.math.divCeil: conform to more test cases 2020-08-28 11:20:42 -04:00
Kate Tsuyu
14b6fb88fb
std.math.divCeil: handle floats correctlier 2020-08-28 09:55:50 -04:00
Kate Tsuyu
aacfef17d5
std.math.divCeil: handle floats correctly 2020-08-28 09:48:40 -04:00
Kate Tsuyu
9dfb917c20
std: Add std.math.divCeil 2020-08-28 08:58:51 -04:00
Frank Denis
ad18078d53 forceEval() -> doNotOptimizeAway() 2020-08-26 10:50:34 +02:00
Frank Denis
0bd53dd203 Rename blackBox, move it to std.mem.forceEval() 2020-08-26 10:50:34 +02:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Andrew Kelley
28a9da8bfc stage2: implement while loops (bool condition)
* introduce a dump() function on Module.Fn which helpfully prints to
   stderr the ZIR representation of a function (can be called before
   attempting to codegen it). This is a debugging tool.
 * implement x86 codegen for loops
 * liveness: fix analysis of conditional branches. The logic was buggy
   in a couple ways:
   - it never actually saved the results into the IR instruction (fixed now)
   - it incorrectly labeled operands as dying when their true death was
     after the conditional branch ended (fixed now)
 * zir rendering is enhanced to show liveness analysis results. this
   helps when debugging liveness analysis.
 * fix bug in zir rendering not numbering instructions correctly

closes #6021
2020-08-13 20:32:32 -07:00
Andrew Kelley
9f5a7d5922 utilize math.ceilPowerOfTwo 2020-08-08 00:39:46 -07:00
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Andrew Kelley
ab9df5b04b stage2: machine code for condbr jumps 2020-07-08 05:35:41 +00:00
antlilja
eb7fad28f8 Improve f128 standard library support
* Add functions: floor128, ceil128, trunc128 and round128
* Add corresponding tests
2020-06-17 18:18:45 +02:00
Andrew Kelley
6b0f7de247 ZIR: add cmp and condbr instructions 2020-05-01 06:47:20 -04:00
Tadeo Kondrak
350b2adacd
std.meta.IntType -> std.meta.Int 2020-04-28 19:11:31 -06:00
Andrius Mitkus
157f566f2d std: make math.clamp work for common uses, remove automatic bounds swapping 2020-04-16 16:19:12 -04:00
LemonBoy
4e95662a4a std: Add qNaN constants 2020-03-24 18:08:53 +01:00
daurnimator
e9c3b65bf4
std: use testing.expectEqual in math.absCast tests 2020-03-05 16:02:26 +11:00
daurnimator
488ba1560f
std: fix math.absCast on i1 2020-03-05 16:00:19 +11:00
LemonBoy
e029032251
std: Use @TypeOf(x,y) as return value for max 2020-03-04 17:21:10 -05:00
Vexu
538d9a5dd8
remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
Vexu
45da72c5b6
remove usages of @typeId, @memberCount, @memberName and @memberType 2020-02-24 23:09:01 +02:00
Hersh Krishna
e7917d099d Add clamp function to math module 2020-01-14 13:06:46 -05:00
Andrew Kelley
5575e2a168
std.mem.compare: breaking API changes
* `std.mem.Compare` is now `std.math.Order` and the enum tags
   renamed to follow new style convention.
 * `std.mem.compare` is renamed to `std.mem.order`.
 * new function `std.math.order`
2020-01-01 18:08:40 -05:00
Andrew Kelley
9468d63819
allow comparison of any numeric types 2019-12-16 11:09:10 -05:00
Shawn Landden
143603b39f
std: lessThan and greaterThan between signed and unsigned
It is a deviation from C, but I think we should consider making this the behavior
of the operators. See #2133
2019-12-16 01:41:26 -05:00