Commit graph

33 commits

Author SHA1 Message Date
Alex Shinn
648f6b9de6 Fix error reporting for complex inequality comparisons.
Closes #934.
2024-05-29 21:36:30 +09:00
Alex Shinn
56ef426dfa Catch division edge case of (/ fx-least -1).
Thanks for Jim Rees for reporting.
2024-02-22 16:32:20 +09:00
Alex Shinn
fae48a3790 properly handling negation of complex numbers with ratio parts (fixes issue #815) 2022-02-22 17:55:54 +09:00
Alex Shinn
82d61b3d8e make mixed inexact/exact ordering consistent, converting to exact for fixnums and ratios instead of just bignums (issue #812) 2022-02-12 07:50:58 +09:00
Alex Shinn
1f0f07114b fix sqrt of complex negative zero (issue #785) 2021-11-07 09:55:24 +09:00
Alex Shinn
23e62275df fixing scheme bytevector for 32bit arch 2020-07-28 15:09:40 +09:00
Alex Shinn
983829cab1 better inexact computation for ratios which overflow double (issue #671) 2020-07-15 16:38:56 +09:00
Kris Katterjohn
eb9d632dbf Fix some NaN comparisons: NaNs are not less than every fixnum
(< +nan.0 n) was yielding #t for fixnum n, and similarly for
(<= +nan.0 n) and (> n +nan.0) and so on.  This also caused
(negative? +nan.0) to return #t.

It just happened that NaNs were less than all fixnums: if a
conditional was written the other way around then NaNs would
have been greater than all fixnums instead.

The flonum case was sort of "accidentally" correct, but if a
conditional was written the other way around then NaNs would
be both less than or equal to and greater than all or equal
to all flonums (but still not equal).

For both cases check for NaNs after getting the flonum values.
2020-07-10 16:49:56 -04:00
Vitaliy Mysak
f449bd157d fix compilation under std=c89
There were few things that prevented successful compilation
using c89 standard. (and other c* standards in case of gcc).
Fix them in this small patch.

Changes in 27/rand.c:
- Use __GNU_SOURCE__ instead of __GNU_LIBRARY__
  or else any of -std=c* options don't work with gcc
- Add a check before using rand_r() as suggested in rand_r(3)
- Move _WIN_32 definitions to "else" branch because it uses the most portable version
2020-05-13 11:12:02 +02:00
Alex Shinn
bbcb571ba5 fix comparison of negative bignums (issue #541) 2019-05-21 22:26:37 +08:00
Alex Shinn
26ceb64434 fix exact neg check for ratio in rounding (issue #539) 2019-05-03 00:37:30 +08:00
Alex Shinn
80bf4013f9 exact zero minus a number is negation (fixes issue #523) 2019-03-05 23:35:15 +08:00
Alex Shinn
2b4394ea74 adding initial support for SRFI 160 uniform vectors 2019-01-15 23:43:50 +08:00
Alex Shinn
11ccfcb5de support exact scaling of bignum literals via moderate sized exponents 2018-12-03 23:05:00 +08:00
Bertrand Augereau
952d7c806b More portable bignums that don't have to rely on gcc 128bit arithmetics extension
SEXP_USE_CUSTOM_LONG_LONGS currently needs SEXP_64_BIT
2018-06-19 04:46:05 +02:00
Bertrand Augereau
d88dfeb172 Fix (expt bignum -k) 2018-06-10 03:21:00 +02:00
Jim Rees
17eb19e43d Changed sexp_double_to_bignum to extract "digits" in base-16 rather
than base 10 so no round-off errors occur at each step.  This is
assuming FLT_RADIX is 2,4,8 or 16.
2018-03-23 10:50:15 -04:00
Jim Rees
b25e46b11b Introduced a second version of sexp_double_to_ratio, named
sexp_double_to_ratio_2, which converts without introducing
round-off errors the way sexp_double_to_ratio does when it
multiplies by 10.

Changed sexp_inexact_to_exact to use this new function when
a non-zero fractional part of the input exists.
2018-03-22 22:19:39 -04:00
John Croisant
e5d9ccb69f Raise type error if remainder called with infinity.
To prevent an infinite loop, raise a type error if the remainder
procedure is called with +inf.0 or -inf.0 as either argument.
2018-03-15 02:42:26 -05:00
okuoku
e092923aac Win32: Fix win32 port
Try to fix win32 port. Now it runs both on Win32/Win64.

Win64 port currently depends on 128bits arithmetic thus it does not run on
MSVC.

Makefile now have EXCLUDE_POSIX_LIBS knob to exclude posix related library
from build.

Introduce msys PLATFORM for Makefile.detect to use MSYS's POSIX
emulation layer. It is intended for linking against MSYS tools; it is
not for embedding to Win32 applications.
2017-11-11 04:31:06 +09:00
Alex Shinn
9c14ee2dea fix complex asin (issue #359) 2016-06-07 23:42:48 +09:00
Alex Shinn
2aa87f4522 fixing complex sqrt near branch cut (issue #353) 2016-06-07 22:47:43 +09:00
Alex Shinn
f5c47c467d preserve -0.0 when added to exact 0 2016-06-07 22:43:49 +09:00
Alex Shinn
8ac14b5f91 Fixing printing of x-0.0i (issue #352). 2016-06-06 22:18:47 +09:00
Alex Shinn
7cb15a7191 Handling exact zero imaginary parts in complex asin.
Fixes issue #350.
2016-06-05 22:25:18 +09:00
Chris Walsh
2005c19ea0 Added full support for packed images, both for static and dynamic libraries. 2016-02-15 21:12:58 -05:00
Alex Shinn
47381d8802 Fix border case in bignum division when the estimate gives a zero
remainder immediately after having overshot the previous estimate.
Fixes issue #303.
2016-02-01 22:06:26 +09:00
Alex Shinn
4fc7181c2c Fix in sexp_bignum_quot_rem when the numerator and divisor are equal.
Fixes issue #269.
2015-06-15 23:31:46 +09:00
Alex Shinn
01df2fec44 Merge pull request #251 from ilammy/overflow-fixes
Fixed a couple of integer overflows
2015-04-15 17:14:58 +09:00
Alex Shinn
4dda923081 Updating copyright years. 2015-04-09 01:28:02 +09:00
ilammy
8329ee9fd6 Do not lose carry bit in addition edge case
Previous code was losing the carry bit in 'all ones' case, when adata[i]
= bdata[i] = SEXP_UINT_T_MAX, and carry = 1 too. In this case expression
(SEXP_UINT_T_MAX - bdata[i] - carry) overflows and yields an incorrect
value SEXP_UINT_T_MAX which results into carry being incorrectly set to
0 after addition.

We need to avoid the second overflow when calculating the new value of
the carry bit. One way to do this is at first check for the overflow in
(adata[i] + bdata[i]), and then throw in the (previous) carry bit.

I have also given "n" more expressive name and added a comment about
the reason why we need that temporary variable.
2015-03-26 02:30:48 +02:00
ilammy
a1ec8ff493 Avoid overflow when doing sexp_fx_abs()
Naturally, fixed-width integer arithmetics can overflow. Chibi handles
it pretty well in general, but one case was missing: it is negation of
the minimal negative number that can be represented as a fixnum. That is,
sexp_fx_neg() must not be applied to sexp_make_fixnum(SEXP_MIN_FIXNUM)
because it overflows and returns an identical fixnum back.

sexp_fx_neg() itself seems to be used right in the current code, but
sexp_fx_abs()--which is defined in terms of sexp_fx_neg()--could be
applied to the forbidden number when used to retrieve an unboxed value
via the sexp_unbox_fixnum(sexp_fx_abs(x)) pattern. So I have added a
separate macro that safely calculates unboxed absolute value of a fixnum,
and replaced sexp_unbox_fixnum(sexp_fx_abs(x)) usages with it.

Current implementation uses two-bit tag for fixnums, plus we need one
bit for the sign, so fixnums have (machine word - 3) significant bits.
Regression tests cover word sizes of 16, 32, 64, and 128 bits (for the
sake of past- and future-proofness).

sexp_bignum_expt() does not have a regression test because we need to
check it with negative exponents like -2^29, so the base must be over
at least 2^(2^29) for the differences to be visible. Fun fact: bignum
representation of such number takes around 1/32 of the available user-
space memory, which makes testing on anything except 32-bit systems
unreasonable (4 TB of RAM anyone?)
2015-03-26 02:30:48 +02:00
Alex Shinn
2922ed591d Forgot to install regexp (patch from Lorenzo) 2015-01-26 08:06:59 +09:00