* math: Setting the bits of floating-point numbers
Added macros which set all 32 bits of a float, the lower 32 bits of
a double, and the upper 32 bits of a double. Some changes were made to
older code to use these macros.
* Replaced code with bitsetting macros in __tan.c3 and tan.c3
* math: tests for word macros and release notes
Tests were written for the word macros, which include getting and
setting a float with a uint and getting and setting the high or low word
of a double with a uint.
Release notes were updated to include the word setter macros.
* net/url: implement url encoding (RFC 3986)
Implement url percent-encoding and -decoding functions according to RFC
3986. Add unit tests.
Link: https://datatracker.ietf.org/doc/html/rfc3986
* net/url: ensure correct encoding of URL components
Add encoding and decoding methods to the Url struct components according
to RFC 3986.
An Url can be parsed from a String with `new_parse()` or `temp_parse()`.
The parsed fields are decoded. The only field that is not decoded is
`raw_query`. To access the decoded query values, use
`Url.query_values()`.
`Url.to_string()` will re-assemble the fields into a valid Url string
with proper percent-encoded values.
If the Url struct fields are filled in manually, use the actual
(un-encoded) values. To create a raw query string, initialize an
`UrlQueryValues` map, use `UrlQueryValues.add()` to add the query
parameters and, finally, call `UrlQueryValues.to_string()`.
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* Add .DS_Store to .gitignore
* Allow <= 999_999 as usec on DateTime (was < 999_999)
* Move [Tz]DateTime .format() to std::time::datetime and import only with libc
* Changed name to DateTimeFormat, prefer function over method. Move names to enum.
* Updated tests to the latest standard.
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
* add std::net::url for parsing/generating URLs
* Move String.index_of_chars into std
* Fix param contract
* Idiomatic type naming, Allman formatting, slicing, document functions
* Use String.tokenize
* Don't return str_view() from freed dstring
* Change indentation to tabs
* Variable casing according to guidlelines
* Updated API and added line to the releasenotes.
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
There are now nolibc definitions for the inverse cosine and inverse
sine.
More test points were added for acos, asin, and atan in the math_tests module.
This was done becuase the nolibc inverse trigonometric functions have
various branching conditions depending on the provided input value. Several
branches in these functions were neglected.
* math_tests: rewrote test_atan()
Rewrote the atan test so that analagous checks are symmetrically
performed for all possible inputs: int, float, and double. The total
number of tests has increased while reducing the total amount of
code.
* math_tests: inverse trig and inverse hyperbolic trig
Tests were written for acos, acosh, asin, asinh, and atanh.
* math: cos macro missing values::promote_int
The cosine macro can't take an integer input without this fix. You can
see that some of the other macros, like the sine macro, have this.
* math_tests: trig and exponential
Wrote tests for the trigonometric macros as well as the
exponential macro. The hyperbolic trig macros use the exponential macro
rather than any LLVM instrinsics (for now at least, LLVM 19 has the proper
compiler intrinsics).
* math: float comparison
In the math module two macros were defined to assist in comparing
floating-point numbers for a given tolerance.
The trig, hyperbolic trig, and exponential tests in the math_tests module
were updated to use these macros instead of direct comparison.
* math: fix adjoint of Matrix2
Fix the adjoint of the Matrix2x2 implementation in the math module. This
also fixes the calculation of the inverse which depends on the adjoint.
* update release notes
Add gcd and lcm functions to calculate the greatest common divisor (gcd)
and the least common multiple (lcm) to the math module. This will also
work for BigInts that implements its own gcd/lcm.
Add inverse, conjugate, and equals functions to the Complex numbers. Add
an IMAGINARY constant to represent the imaginary unit. Also, add unit
tests for different types.
* sort: add is_sorted
Add is_sorted function to check whether a list is sorted or not. Sort
order (ascending or descending) will be detected by looking at the data.
Add tests.
* update the release notes
* refactor: use lambda
* sort: extract partition from quicksort
Extract the partition logic from quicksort into a macro. This allows to
reuse the partition logic for, e.g., the quickselect algorithm.
* sort: implement quickselect
implement Hoare's selection algorithm (quickselect) on the basis of the
already implemented quicksort. Quickselect allows to find the kth
smallest element in a unordered list with an average time complexity of
O(N) (worst case: O(N^2)).
* add quicksort benchmark
Create a top-level benchmarks folder. Add the benchmark implementation
for the quicksort algorithm.
Benchmarks can then be run in the same way as unit tests from the
root folder with:
c3c compile-benchmarks benchmarks/stdlib/sort
Ensure that the URL alphabet for base64 is used with the urlencode
functions (urlencode, urlencode_buffer, urlencode_temp and
urlencode_new) are used. Add a new test.
Fix the base64 decoding. If there's an 'A' character in the encoded
text, the base64 decode function returns an INVALID_PADDING error. The
reason lies in the way Base64Decoder.init tries to find a suitable
invalid character. Fix this by defining the invalid character as 0xff
(which is already the case for a decoding without padding).
This error has not been caught by the test harness, because no test
contains an 'A' character in the the encoded text yet. Add a new test.
* io: implement MultiReader struct
Implement a MultiReader (InStream) which sequentially read from the
provided readers (InStreams). Return IoError.EOF when all of the readers
are read.
* io: implement MultiWriter struct
Implement a MultiWriter (OutStream). The MultiWriter duplicates its
writes to all the provided writers (OutStream).
* io: implement TeeReader struct
Implement a TeeReader (InStream) which reads from a wrapped reader
(InStream) and writes data to the provided writer (OutStream).