Commit Graph

123 Commits

Author SHA1 Message Date
Marc Tiehuis
78af62a19a Pack big.Int sign and length fields
This effectively takes one-bit from the length field and uses it as the
sign bit. It reduces the size of an Int from 40 bits to 32 bits on a
64-bit arch.

This also reduces std.Rational from 80 bits to 64 bits.
2019-04-11 19:36:35 +12:00
Marc Tiehuis
87d8ecda46 Fix math.big.Int divN/gcdLehmer and fuzz-test failures 2019-04-11 19:36:35 +12:00
Marc Tiehuis
30788a98b1 Handle zero-limb trailing div case in big.Int 2019-04-11 19:36:35 +12:00
Marc Tiehuis
d3e1f32362 Small fixes for big.Rational and corrections for gcdLehmer
The int div code still causes some edge cases to fail right now.
2019-04-11 19:36:35 +12:00
Marc Tiehuis
b3ecdfd7bf Fix big.Int toString maybe-null allocator 2019-04-11 19:36:35 +12:00
Marc Tiehuis
5f4fcd5030 Add initial big.Rational type 2019-04-11 19:36:35 +12:00
Marc Tiehuis
ea1d2a2409 Add read-only, non-allocating Int for internal constants
A constant Int is one which has a value of null for its allocator field.
It cannot be resized or have its limbs written. Any attempt made to
write to it will be caught with a runtime panic.
2019-04-11 19:36:35 +12:00
Shawn Landden
aecbd1892a Simplify math.isnan
We can just rely on the builtin behavior.
2019-04-05 11:03:57 -04:00
Shawn Landden
85d1885375 std.mulWide() whose return is twice as wide 2019-03-28 15:51:10 -04:00
Andrew Kelley
9c13e9b7ed
breaking changes to std.mem.Allocator interface API
Before, allocator implementations had to provide `allocFn`,
`reallocFn`, and `freeFn`.

Now, they must provide only `reallocFn` and `shrinkFn`.
Reallocating from a zero length slice is allocation, and
shrinking to a zero length slice is freeing.

When the new memory size is less than or equal to the
previous allocation size, `reallocFn` now has the option
to return `error.OutOfMemory` to indicate that the allocator
would not be able to take advantage of the new size.

For more details see #1306. This commit closes #1306.

This commit paves the way to solving #2009.

This commit also introduces a memory leak to all coroutines.
There is an issue where a coroutine calls the function and it
frees its own stack frame, but then the return value of `shrinkFn`
is a slice, which is implemented as an sret struct. Writing to
the return pointer causes invalid memory write. We could work
around it by having a global helper function which has a void
return type and calling that instead. But instead this hack will
suffice until I rework coroutines to be non-allocating. Basically
coroutines are not supported right now until they are reworked as
in #1194.
2019-03-15 17:57:21 -04:00
Andrew Kelley
e402455704
rename std lib files to new convention 2019-03-02 16:46:04 -05:00
Sahnvour
4bac22e888 all integers returned by @typeInfo are now comptime_int 2019-03-02 14:27:37 -05:00
Benoit Jauvin-Girard
fcf65f06c4 Fix std.math.powi so powi(x, +-0) = 1 for any x. 2019-02-17 14:52:40 -05:00
Marc Tiehuis
cf007e37b9 Add f128 support for fabs, isinf, isnan, inf and nan functions 2019-02-13 23:27:23 +13:00
Andrew Kelley
c2db077574
std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.

This makes release mode test builds more accurately test
the actual code that will be run.

However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.

Here is the explanation of when to use either one, copied from
the assert doc comments:

Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.

closes #1304
2019-02-08 18:23:38 -05:00
Andrew Kelley
404c87b06a
fix incorrect parameter names for std.math.atan2 2019-01-14 18:11:17 -05:00
Wink Saville
634d11ab28 Add add compiler_rt routines for float to signed integer conversion
And add std.math.f128_* constants.

The routines are:

  __fixdfdi, __fixdfsi, __fixdfti,
  __fixsfdi, __fixsfsi, __fixsfti,
  __fixtfdi, __fixtfsi, __fixtfti.

These all call fixint which is a generic zig function that does the
conversion:

  pub fn fixint(comptime fp_t: type, comptime fixint_t: type, a: fp_t) fixint_t

There are also a set tests:

  __fixdfdi_test, __fixdfsi_test, __fixdfti_test,
  __fixsfdi_test, __fixsfsi_test, __fixsfti_test,
  __fixtfdi_test, __fixtfsi_test, __fixtfti_test.
2018-12-12 00:21:42 -05:00
Andrew Kelley
7005ec5efe
Revert "Add math min/max for Float and Value"
This reverts commit 078a0a6999.

On closer inspection, I'm not sure these values for float min/max
make sense. Why is it max instead of true_max? Why isn't it positive
and negative infinity?

Let's discuss further before committing to these changes.
2018-11-29 09:33:47 -05:00
Wink Saville
078a0a6999 Add math min/max for Float and Value 2018-11-28 23:13:12 -05:00
daurnimator
2baf0e2ffc add std.math.IntFittingRange 2018-11-27 10:19:06 -05:00
Vallentin
398914eb71 Fixed typos 2018-11-16 14:03:39 -05:00
Jimmi Holst Christensen
8139c5a516
New Zig formal grammar (#1685)
Reverted #1628 and changed the grammar+parser of the language to not allow certain expr where types are expected
2018-11-13 05:08:37 -08:00
emekoi
c7799ff2b2 fixed comments 2018-10-27 12:58:40 -05:00
Andrew Kelley
2b395d4ede
remove @minValue,@maxValue; add std.math.minInt,maxInt
closes #1466
closes #1476
2018-10-26 15:01:51 -04:00
Andrew Kelley
d5648d2640
remove implicit cast from T to *const T
closes #1465
2018-10-15 18:23:47 -04:00
Jimmi Holst Christensen
378d3e4403
Solve the return type ambiguity (#1628)
Changed container and initializer syntax
* <container> { ... } -> <container> . { ... }
* <exrp> { ... } -> <expr> . { ...}
2018-10-15 09:51:15 -04:00
emekoi
a22d9daaec added math.pow support for integer types. resolves #1637 (#1642)
added math.powi for integers; pow now handles ints
2018-10-10 10:50:23 -04:00
Andrew Kelley
d40c4e7c89
Merge pull request #1429 from shawnl/arm64
initial arm64 support
2018-10-06 00:11:39 -04:00
Andrew Kelley
275b4100c0
remove unnecessary setFloatMode calls
Now that Strict is the default, these calls only add noise.
2018-09-18 15:15:03 -04:00
Andrew Kelley
a2abdb185f
Merge remote-tracking branch 'origin/master' into llvm7 2018-09-16 10:51:58 -04:00
Andrew Kelley
c06a61e9bf
remove this. add @This().
closes #1283
2018-09-13 16:34:33 -04:00
Marc Tiehuis
e70c543bc4 math/complex: cexp test correction and ldexp usage fix 2018-09-13 20:33:05 +12:00
Shawn Landden
f8808edff4 simplify f64_min to equivilent value
arm64 complains about the old value (I added a test)
2018-09-08 03:52:28 +00:00
Andrew Kelley
7109035b78 Merge remote-tracking branch 'origin/master' into llvm7 2018-08-25 21:57:28 -04:00
Marc Tiehuis
353419f82d Default to strict IEEE floating point
Closes #1227.
2018-08-23 22:54:46 +12:00
Andrew Kelley
dd9728c5a0 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-24 00:43:12 -04:00
Andrew Kelley
5a919dd82d Merge remote-tracking branch 'origin/master' into self-hosted-libc-hello-world 2018-07-23 14:32:13 -04:00
Andrew Kelley
99153ac0aa add std.math.big.Int.fitsInTwosComp
so that we can pass runtime-known values
2018-07-22 10:58:45 -04:00
Marc Tiehuis
d53fae3551 Add big int fits function (#1279)
Returns whether the current value in an Int fits in the requested type.
2018-07-22 10:11:27 -04:00
Marc Tiehuis
07b6a3d335 Tighten Int.to bounds and add twos-complement bitcount 2018-07-22 17:47:57 +12:00
Andrew Kelley
f5a67dba08 self-hosted: implicit cast comptime ints to other ints
we now have successful exit codes from main linking
against libc
2018-07-20 01:46:49 -04:00
Andrew Kelley
1d85b588ea self-hosted: progress on IR for supporting libc hello world
* add c int types
 * some more ir stubs
2018-07-19 00:08:47 -04:00
Andrew Kelley
558b0b8791 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-16 13:37:16 -04:00
Andrew Kelley
e9a03cccf3 all integer sizes are available as primitives
* fix wrong implicit cast for `@IntType` bit_count parameter.
 * fix incorrect docs for `@IntType` bit_count parameter.

closes #1242
closes #745
closes #1240
2018-07-16 10:53:15 -04:00
Andrew Kelley
6e1425e312 Merge remote-tracking branch 'origin/master' into llvm7 2018-07-02 20:00:13 -04:00
Ben Noordhuis
30cfc0ab2c test std.math f16 sqrt support
refs #1122
2018-06-30 01:58:17 +02:00
Ben Noordhuis
be36179064 add std.math f16 signbit support
refs #1122
2018-06-30 01:58:17 +02:00
Ben Noordhuis
ca444e6191 add std.math f16 copysign support
refs #1122
2018-06-30 01:58:17 +02:00
Ben Noordhuis
d293f1a0ed add std.math f16 floor support
refs #1122
2018-06-30 01:58:17 +02:00
Ben Noordhuis
1abc925292 add std.math f16 fabs support
refs #1122
2018-06-30 01:58:17 +02:00