Frozen Emscripten SDK libc source comment notices.

Complete comment blocks are retained without translation from the selected libc/libc_optz C sources and a conservative musl header superset. Source coverage does not assert every file is linked. Aggregate musl COPYRIGHT and Emscripten/LLVM licenses accompany this file.


=== system/lib/libc/compat/__synccall.c ===
SHA256: 3fa665c2b7cfc779fffcc7eb6bd1f0bb0a9c90eadf409ce2e1b842406261ab34
Primary Git blob: 50b028efbf3f15178a2b458d93e1eb518e31e65a
// just do it, until we have full pthreads


=== system/lib/libc/compat/aligned_alloc.c ===
SHA256: 938c70afbda3db3843a721e45d484f6c2ea25ac92b975fbe2c884c36cf3e7a3a
Primary Git blob: 172008d5d928f0ebe8608a507e2147a85c4b73d2
// Musl has an aligned_alloc routine, but that builds on top of standard malloc(). We are using dlmalloc, so

// we can route to its implementation instead.


=== system/lib/libc/dynlink.c ===
SHA256: 295e5bca9f83dc2cbbc9dc8691c68f41d44d388d60000c0aa56ad59df51f850f
Primary Git blob: 786c8ba70c8a319ad1f37a09ebb68c5057a1027b
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 *
 * Emscripten-specific version dlopen and associated functions.  Some code is
 * shared with musl's ldso/dynlink.c.
 */

//#define DYLINK_DEBUG

// We maintain a list of all dlopen and dlsym events linked list.

// In multi-threaded builds this is used to keep all the threads in sync

// with each other.

// In single-threaded builds its only used to keep track of valid DSO handles.

// Symbol index resulting from dlsym call. -1 means this is a dso event.

// dso handler resulting from dlopen call.  Only valid when sym_index is -1.

// Handle to "main" dso, needed for dlopen(NULL,..)

// Once we have the lock we want to avoid automatic code sync as that would

// result in a deadlock.

// _REENTRANT

// insert into linked list

// Block until all other threads have loaded this module.

// TODO: figure out some way to tell when its safe to free p->file_data.  Its

// not safe to do here because some threads could have been asleep then when

// the "dlsync" occurred and those threads will synchronize when they wake,

// which could be an arbitrarily long time in the future.

// If the file exists in the filesystem, load it here into linear memory which

// makes the data available to JS, and to other threads.  This data gets

// free'd later once all threads have loaded the DSO.

// When we are attempting to synchronize loaded libraries between threads we

// currently abort, rather than rejecting the promises.  We could reject the

// promises, and attempt to return an error from the original dlopen() but we

// would have to also unwind the state on all the threads that were able to load

// the module.

// Load the next dso in the list

// Called on the main thread to asynchronously "catch up" with all the DSOs

// that are currently loaded.

// Process any dlsym events synchronously until we find a dlopen event

// All dso loaded

// Unlock happens once all DSO have been loaded, or one of them fails

// with sync_one_onerror.

// Called on background threads to synchronously "catch up" with all the DSOs

// that are currently loaded.

// Should only ever be called from a background thread.

// If any on the libraries fails to load here then we give up.

// TODO(sbc): Ideally this would never happen and we could/should

// abort, but on the main thread (where we don't have sync xhr) its

// often not possible to synchronously load side module.

// Called when a thread exists prior to being able to completely sync operation.

// We can just ignore this case and report success.

// Called once do_thread_sync completes

// Proxying queue specially for handling code loading (dlopen) events.

// Initialized by the main thread on the first call to

// `_emscripten_proxy_dlsync` below, and processed by background threads

// that call `_emscripten_process_dlopen_queue` during futex_wait (i.e. whenever

// they block).

// Asynchronously runs _emscripten_dlsync_self on the target then and

// resolves (or rejects) the given promise once it is complete.

// This function should only ever be called by the main runtime thread which

// manages the worker pool.

// If we failed to proxy, then the target thread is no longer alive and no

// longer needs to be caught up, so we can resolve the promise early.

// If the target thread is in the sleeping state (and this check is

// performed after the enqueuing of the async work) then we know its safe to

// resolve the promise early, since the thread will process our event as

// soon as it wakes up.

// _REENTRANT

// Modified version of path_open from musl/ldso/dynlink.c

/* Any negative value but -1 will inhibit
         * further path search. */

// Resolve filename using LD_LIBRARY_PATH

// Absolute path, leave it alone

// Search for library name to see if it's already loaded

// Internal version of dlopen with typed return value.

// Without this, the compiler won't tell us if we have the wrong return type.

// If a null pointer is passed in path, dlopen() returns a handle equivalent

// to RTLD_DEFAULT.

// For async mode

// Unlock happens in dlopen_onsuccess/dlopen_onerror

// emscripten_dlopen_promise is currently implemented on top of the callback

// based API (emscripten_dlopen).

// TODO(sbc): Consider inverting this and perhaps deprecating/removing

// the old API.

// Create a promise that is resolved (and destroyed) once the operation

// succeeds.

// Create a second promise bound the first one to return the caller.  It's

// then up to the caller to destroy this promise.

// The order matters here. Calling emscripten_dlopen before resolving the second promise

// may destroy the first promise before resolving the value.

// The first "dso" is always the default one which is equivalent to

// RTLD_DEFAULT.  This is what is returned from `dlopen(NULL, ...)`.

// Block until all other threads have loaded this module.


=== system/lib/libc/emscripten_console.c ===
SHA256: b9a499a0e89e8c8e9840995f8ebd35f86b9fc2c2a8a50f9e3cbcd6aa741ae132
Primary Git blob: 3a41d0d70c3ee385b00d6cc12775147da2861bee
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// Note: we have to inline `vlogf` here instead of using it, because

// `_emscripten_log_formatted` has a different signature than the

// `callback` parameter of `vlogf`, and we can't use it without a callback

// as we need `alloca` to remain on stack.


=== system/lib/libc/emscripten_fiber.c ===
SHA256: 424f38972dc0f1d3c3b1b3ddd178ec031595bbcb428d3f75f0e2bc539de8bc67
Primary Git blob: e674421117eded72fee30b67be245f2a1de622e6
// Copyright 2022 The Emscripten Authors.  All rights reserved.

// Emscripten is available under two separate licenses, the MIT license and the

// University of Illinois/NCSA Open Source License.  Both these licenses can be

// found in the LICENSE file.


=== system/lib/libc/emscripten_get_heap_size.c ===
SHA256: f642e9c8e89121b3c379535996cb78d8a7fa0626ef8351d7b00c1824dcdb1dbe
Primary Git blob: bc39a05df8ae9c7cd09f6eb3b0c90d8f4c706c92
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/emscripten_memcpy.c ===
SHA256: 1eed22a14ee2143283ad19a0494355734bd9d48a19b318b605c86f274642afa0
Primary Git blob: 7e30f567463c2bc5443743bbc8d231556a69de7e
/*
 * A simple memcpy optimized for wasm.
 */

// Use the simple/naive version of memcpy when building with asan

// TODO: Ensure this is inlined with Binaryen or inline asm

// TODO: Re-investigate the size threshold to enable this

// The initial unaligned < 4-byte front.

// TODO: we could use 64-bit ops here, but we'd need to make sure the

//       alignment is 64-bit, which might cost us

// In the unaligned copy case, unroll a bit as well.

// The remaining unaligned < 4 byte tail.


=== system/lib/libc/emscripten_memcpy_bulkmem.S ===
SHA256: 39af87c7ef0479fa2c4863838b4012a8ed86e89d6e37035c1054666731ffc016
Primary Git blob: 876b997944893e5b792b3ef810012246de829c2f
// memory.copy traps on OOB zero-length copies, but memcpy must not.


=== system/lib/libc/emscripten_memmove.c ===
SHA256: 9cb5224eafe928a4e518865f4613477141fa462920df1824bf6dbbd2650ab5d9
Primary Git blob: 2d12280698f7fa028faf2b21e5a0852b1285aa6f
// XXX EMSCRIPTEN ASAN: build an uninstrumented version of memmove


=== system/lib/libc/emscripten_memset.c ===
SHA256: 7f345bf7ffbb49e3d7e1691538a243471e67e0e11c9e06b518c2b691295b1cdf
Primary Git blob: 111a99f495e6295a78d6bae0ea676636655f2a45
// for emscripten_memset_big

// build an uninstrumented version of memset


=== system/lib/libc/emscripten_memset_bulkmem.S ===
SHA256: b00f4e7cc25443722c1d568a6049c0e5c5a31eb7a2ae699b4d04bad7d199a0b9
Primary Git blob: ba8d91bb0ae8f0912b49b168b2d2f7455bff63c6
// memory.fill traps on OOB zero-length sets, but memset must not.


=== system/lib/libc/emscripten_mmap.c ===
SHA256: 546f706a1509dfad56bf3cacb844211fea12f5ee629332fc492c87a514482dd4
Primary Git blob: 7281d5b8baebee6eb22487a69ae30d2903922926
/*
 * Copyright 2022 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// Linked list of all mapping, guarded by a musl-style lock (LOCK/UNLOCK)

// We don't support partial munmapping.

// Remove map from linked list

// Release the memory.

// Success!

// We don't currently support location hints for the address of the mapping

// MAP_ANONYMOUS (aka MAP_ANON) isn't actually defined by POSIX spec,

// but it is widely used way to allocate memory pages on Linux, BSD and Mac.

// In this case fd argument is ignored.

// For anonymous maps, allocate that mapping at the end of the region.


=== system/lib/libc/emscripten_scan_stack.c ===
SHA256: f8bd7b2e47d1f1bd445ecbcd18d2109a4f016e60be4b1f1133e5ffb56ca9ca6f
Primary Git blob: c5a4417830c838fd9eed61851fea57452ec1a943
/*
 * Copyright 2020 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/emscripten_time.c ===
SHA256: fd8c2b05393d66364bf6d7f67428bb0ef553ef523be4338ed8ec316111bf9355
Primary Git blob: 1cfe02cdca40e891785e26ed39a28500320380b1
/*
 * Copyright 2022 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// For `emscripten_date_now`

// For `weak`

// emscripten-specific implementations. These works out slightly smaller than

// musl's since it they avoid depending on the more general clock_gettime.

// seconds

// microseconds

// Non-standard glibc/BSD extension that is not implemented by musl


=== system/lib/libc/emscripten_yield_stub.c ===
SHA256: 136bb376f4edc9fd7ef85fc42b6767e8780d5602e26a143062dd251361767cc8
Primary Git blob: ac0d7498e7674739eba7e25d62a6bfb963e3ffd5
/*
 * Copyright 2026 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/kill.c ===
SHA256: 1b700ecd4b4f8b7baf07fc7fa728cb3fc73f9d1c55b40d95f6845ecd0bf1580a
Primary Git blob: e21537d3c84e1018ca16acfd4f3c920fa58eb8e6
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/lookup_name.c ===
SHA256: 163333d1809a53e2259fb9f2465fba875ae12ee9d50297b0a2138b7a14a9fba7
Primary Git blob: 904391b5974b9fa610a1caceaea4f45099041015
// Emscripten-specific version of musl/src/network/lookup_name.c

/* We currently only support the callsite in gethostbyname2_r which
	 * passes AI_CANONNAME.  Remove this assertion if we ever expand
	 * this support. */

/* This hunk is duplicated from musl/src/network/lookup_name.c */

/* reject empty name and check len so it fits into temp bufs */

/* We only support a single address */


=== system/lib/libc/mktime.c ===
SHA256: 432b2b857210e487240f4e6826b8e31710bb1b26d9741ecd470d406d02268281
Primary Git blob: 258a75c1b75d15eac602fe7416704e669a7c721f
/*
 * Copyright 2023 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// __localtime_js sets everything but the tmzone pointer


=== system/lib/libc/musl/arch/emscripten/bits/alltypes.h ===
SHA256: 7ba9f915c7f0aa0b4eafeaca1cb621fc52fe9d96da2de4073e71ba7d4d4773fc
Primary Git blob: 051245ed475d9c5321a474d29c596a4f50e54e4c
/*
 * The .h version of this file is generated from the .h.in.
 * See update_alltypes.sh.
 */

// XXX EMSCRIPTEN: ensure it's always 32-bits even in wasm64

// For canvas transfer implementation in Emscripten, use an extra control field

// to pass a pointer to a string denoting the WebGL canvases to transfer.

// END EMSCRIPTEN-SPECIFIC DEFINITIONS

//

// Below here are the shared musl definitions.  The emscripten-specific definitions above will take precedence

// due to the `__DEFINED_` macro system.


=== system/lib/libc/musl/arch/emscripten/bits/errno.h ===
SHA256: be2a71d49f18d8d844260a048aa5c9133d23ee499cd3495054ce28251cb669af
Primary Git blob: 43a8a6bac049befc488b3bfc1b88585d6c8f0457
// Codes without a wasi equivalent, make sure they start

// above the wasi ones, which are dense [1,76].

// Also try to fit the codes in a single byte signed wasm SLEB.

// codes which musl defines as aliases


=== system/lib/libc/musl/arch/emscripten/bits/stat.h ===
SHA256: ac9231d33af9e7036bf8d7bf5016d2f73a79e1f96d2b854a110909c2c618b403
Primary Git blob: bfa9a597bcf6d50fd729f967f2acf3afded6008a
/* copied from kernel definition, but with padding replaced
 * by the corresponding correctly-sized userspace types. */


=== system/lib/libc/musl/arch/emscripten/syscall_arch.h ===
SHA256: 32bcfa4e044f0c58f2dfbd3a57d9f33c540a5e9761ba08cb8df3dc6d9e3e0283
Primary Git blob: 64e6cea850d810aa6b2535e9b47c1743f1f39cea
// Compile as if we can pass uint64 values directly to the

// host.  Binaryen will take care of splitting any i64 params

// into a pair of i32 values if needed.

// mode is optional


=== system/lib/libc/musl/include/arpa/telnet.h ===
SHA256: 4dc41f35778e57506923be0ab1bc15716b96e47e19ee2757753696ec640b7d00
Primary Git blob: e2ad97429520738e307a52bdbe90c9aaf0b1eccf
/* Authenticate */


=== system/lib/libc/musl/include/fcntl.h ===
SHA256: 80b575ae15a62020a8d223af333ddba14dccd720f7a045523d9ff655dee666f3
Primary Git blob: cce43031f112d022c657234202eeb5de65558ee6
// EMSCRIPTEN


=== system/lib/libc/musl/include/features.h ===
SHA256: 078acf7161200b03710cdf93f039f6dbfed993ec619f16ea902a41871c228603
Primary Git blob: 952ffd968592b20e1bfcce2a4d613c7a1c1d0350
// In emscripten the LFS functions are kept around when _GNU_SOURCE is

// defined, for increased compatabiliy. This is also what glibc does.


=== system/lib/libc/musl/include/inttypes.h ===
SHA256: 68064c64ec3303bd27ee6ff514b945bcf910b82c3d63c5ddd6c351a836d78543
Primary Git blob: 90c35c8664ae88f086ef2217c4ca259e5c8e5b8d
// Under emscripten __PTRDIFF_TYPE__ and therefor intptr_t are defined to

// be `long int` even on wasm32.


=== system/lib/libc/musl/include/limits.h ===
SHA256: 54d66aac63111f27a6b6584ee91711ecdcfbb26b730ab0cf744d8a05503b27c7
Primary Git blob: a1365cfc15e2238ede846a935dfa1145f63cd8f1
/* __LONG_MAX */

/* Support signed or unsigned plain-char */

// We depend on the JS API to reteive the local name for the current

// timezone and this can sometimes exceed 6 chars.  For example:

// TZ='Asia/Kathmandu' yields 'GMT+5:45'.

/* Implementation choices... */

/* Arbitrary numbers... */

/* POSIX/SUS requirements follow. These numbers come directly
 * from SUS and have nothing to do with the host system. */


=== system/lib/libc/musl/include/math.h ===
SHA256: 5559892c51d9625616fde0c4d25609f1e68e0aa3aee090d1842c6f894e63352a
Primary Git blob: 14f28ec8c646596aee2d78c662a65584def559a1
/* e */

/* log_2 e */

/* log_10 e */

/* log_e 2 */

/* log_e 10 */

/* pi */

/* pi/2 */

/* pi/4 */

/* 1/pi */

/* 2/pi */

/* 2/sqrt(pi) */

/* sqrt(2) */

/* 1/sqrt(2) */


=== system/lib/libc/musl/include/net/if_arp.h ===
SHA256: 74c50186936542bbe8c7c284734e52d9b397acafdeaba8bbbcec8b8ac30c7509
Primary Git blob: 27becc835eeb458830f990fbb29621a8229e694d
/* Nonstandard header */


=== system/lib/libc/musl/include/netdb.h ===
SHA256: 6f069a2a0a72a1e03866f426cc6a03990e6bfe3b601215e7b7780b6536c8f50b
Primary Git blob: 3af065e2b6b5e8a796a06df7fcaa28738ab78e25
/* Legacy functions follow (marked OBsolete in SUS) */


=== system/lib/libc/musl/include/resolv.h ===
SHA256: adcdb3600df635f2b6fee42987e33f3ca7a8a1e142d2f2b5d83be6fb585e8453
Primary Git blob: 8b23ad66cc7613a68e670c95c2b409273fdc05a5
/* unused; purely for broken apps */


=== system/lib/libc/musl/include/scsi/sg.h ===
SHA256: affb61e1e89c8b32f962141d050268040648eae02d9e546b2fb5d039d57e951f
Primary Git blob: a7ac247e3ffade1a20770e2bc90119c7756eaf83
/* 60*HZ */


=== system/lib/libc/musl/include/setjmp.h ===
SHA256: 55c79a99860da4e2fe1e5a2687de80c34482425207d522d479ef8a8a34c0703b
Primary Git blob: af72c80cdbce0da295812359f8d23ec5c4462d29
/* XXX EMSCRIPTEN: No signals support, alias sigsetjmp and siglongjmp to their non-signals counterparts. */


=== system/lib/libc/musl/include/signal.h ===
SHA256: 18a55cd40db16c4ee993521d53f288e1a4537b9ccb31ab43c35c9a1e2a24f947
Primary Git blob: e75cb860a3f6dde803b0b52afed57d257c5a7de8
/* XXX EMSCRIPTEN: use -2 since 1 is a valid function address */


=== system/lib/libc/musl/include/stdalign.h ===
SHA256: 54289e3284182b1a521dd7f8bdd8e9f4b2a85879b8da761b4ad8c421598a12f1
Primary Git blob: 2cc94be3f6d7e4b65839cbcd35a1e5286139e4c8
/* this whole header only works in C11 or with compiler extensions */


=== system/lib/libc/musl/include/stdio.h ===
SHA256: 14d89974ef0227b6ea8f000ef93a283efcdc8c852b511c00a9850b5b0a1689b9
Primary Git blob: 609fad5fdff3e4ce5e4774e13b1191c92d9e6ebb
// EMSCRIPTEN


=== system/lib/libc/musl/include/sys/resource.h ===
SHA256: 72450db0aa279bc66100654c177e1d16475a52cc32848156f1c6cff44a3fc836
Primary Git blob: e8bfbe1f08dc12347c0db10feadef86f6e10710f
/* linux extentions, but useful */

/* room for more... */


=== system/lib/libc/musl/include/tgmath.h ===
SHA256: 7c4b6a2e99f4e72a6ebad763ac452c60fede23e99f27106ab3b03edf24b60769
Primary Git blob: e41ccac9ec54cc038ed4b4b33bc64544cb396606
/*
the return types are only correct with gcc (__GNUC__)
otherwise they are long double or long double complex

the long double version of a function is never chosen when
sizeof(double) == sizeof(long double)
(but the return type is set correctly with gcc)
*/

/* return type */

/*
the result must be casted to the right type
(otherwise the result type is determined by the conversion
rules applied to all the function return types so it is long
double or long double complex except for integral functions)

this cannot be done in c99, so the typeof gcc extension is
used and that the type of ?: depends on wether an operand is
a null pointer constant or not
(in c11 _Generic can be used)

the c arguments below must be integer constant expressions
so they can be in null pointer constants
(__IS_FP above was carefully chosen this way)
*/

/* if c then t else void */

/* if c then t1 else t2 */

/* cast to double when x is integral, otherwise use typeof(x) */

/* 2 args case, should work for complex types (cpow) */

/* 3 args case (fma only) */

/* drop complex from the type of x */

/* TODO: wrong when sizeof(long double)==sizeof(double) */

/* add complex to the type of x */

/* function selection */

/* special cases */

/* suppress any macros in math.h or complex.h */

/* tg functions */


=== system/lib/libc/musl/include/unistd.h ===
SHA256: 7167ff608601a519c99c9beba65f956d4d4d6911def339513b1f235bbd5ee49f
Primary Git blob: 73a075c24dd47739ecee04263d6ac9c1d1ff0d08
// EMSCRIPTEN

/* XXX EMSCRIPTEN long syscall(long, ...); */

/* XXX Emscripten doesn't always support pthreads */

/* !! */

/* !! */


=== system/lib/libc/musl/src/complex/__cexp.c ===
SHA256: ffcf569466b0ac3defff943c989b6b181c7c41dc4f9538c32944459a5272203b
Primary Git blob: 003d20af6efb72252438b68d88c0c39e19bb27b3
/* origin: FreeBSD /usr/src/lib/msun/src/k_exp.c */

/*-
 * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* constant for reduction */

/* k * ln2 */

/*
 * Compute exp(x), scaled to avoid spurious overflow.  An exponent is
 * returned separately in 'expt'.
 *
 * Input:  ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91
 * Output: 2**1023 <= y < 2**1024
 */

/*
	 * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to
	 * minimize |exp(kln2) - 2**k|.  We also scale the exponent of
	 * exp_x to MAX_EXP so that the result can be multiplied by
	 * a tiny number without losing accuracy due to denormalization.
	 */

/*
 * __ldexp_cexp(x, expt) compute exp(x) * 2**expt.
 * It is intended for large arguments (real part >= ln(DBL_MAX))
 * where care is needed to avoid overflow.
 *
 * The present implementation is narrowly tailored for our hyperbolic and
 * exponential functions.  We assume expt is small (0 or -1), and the caller
 * has filtered out very large x, for which overflow would be inevitable.
 */

/*
	 * Arrange so that scale1 * scale2 == 2**expt.  We use this to
	 * compensate for scalbn being horrendously slow.
	 */


=== system/lib/libc/musl/src/complex/__cexpf.c ===
SHA256: 3cedd5c25cc80d78713bd44c53c7f3170dad26fde14ea5eb3b0028bfede24517
Primary Git blob: ee5ff2bce7e8f10f4af7f7c79bdfaf19d329b5ae
/* origin: FreeBSD /usr/src/lib/msun/src/k_expf.c */

/*-
 * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* constant for reduction */

/* k * ln2 */

/*
 * See __cexp.c for details.
 *
 * Input:  ln(FLT_MAX) <= x < ln(2 * FLT_MAX / FLT_MIN_DENORM) ~= 192.7
 * Output: 2**127 <= y < 2**128
 */


=== system/lib/libc/musl/src/complex/cacos.c ===
SHA256: fcb046caddea093996fd0e8cf5a9ce5e4f767ebce00dd1d8a52c2c3f466a3e86
Primary Git blob: c39d257b44b52a679a4e6efe61a38eef739e5b3e
// FIXME: Hull et al. "Implementing the complex arcsine and arccosine functions using exception handling" 1997

/* acos(z) = pi/2 - asin(z) */


=== system/lib/libc/musl/src/complex/cacosf.c ===
SHA256: 9e8b49a8b55858582fecfd1dffc5d2ecfaa5f5f4edc8f788f6dbd1cdd4aff0d1
Primary Git blob: ed8acf0f5a0161675da8692ba90112afc760c186
// FIXME


=== system/lib/libc/musl/src/complex/cacosh.c ===
SHA256: 5146ca8e871e0776ea2b0b410b1dc6d672ef48ee6fe14e7a8353db2c103191d2
Primary Git blob: 76127f75f4bb1b4369bf98d209c0089e2ff86bca
/* acosh(z) = i acos(z) */


=== system/lib/libc/musl/src/complex/cacosl.c ===
SHA256: 3672638e4f2d99434367a15123149cead69cb36b32345c037833438355d13a4a
Primary Git blob: cc20dcd7d954dad8c681bcba7a6ec6767c554636
// FIXME


=== system/lib/libc/musl/src/complex/casin.c ===
SHA256: 2e04a7209c37e5a555290ec6713d0a312fd33996a5f7a9c23b3fb7bddb1a4503
Primary Git blob: 3244bebb169349d946a63bd2b7e984be75821294
// FIXME

/* asin(z) = -i log(i z + sqrt(1 - z*z)) */


=== system/lib/libc/musl/src/complex/casinf.c ===
SHA256: 0e3e15d826eda1fef3dcd02a61cb75b4a389f197deeac8e0c558f9e28f1de3c7
Primary Git blob: 2cda2f086b252dd49378efbfe0c7b2074701d455
// FIXME


=== system/lib/libc/musl/src/complex/casinh.c ===
SHA256: 791dacdbba5b8c071178bae61ba0c3c664476c56b036a2e2988f912649121c7b
Primary Git blob: 50bf27ce88ea426e67fec4f140560ac5445067a9
/* asinh(z) = -i asin(i z) */


=== system/lib/libc/musl/src/complex/casinl.c ===
SHA256: 3e1f1df8337d2785bffeaeea281f8f0cdc1a5380070b357bb313c93991f127a8
Primary Git blob: 072adc450d2b0ac6c224c734469b3b82f79d537a
// FIXME


=== system/lib/libc/musl/src/complex/catan.c ===
SHA256: 056cc1842d173fe90297adb4c088745cb3bcb37c95b56d72c246ae505e470eb5
Primary Git blob: ccc2fb539af799f97c4411c4e820de23d43797b8
/* origin: OpenBSD /usr/src/lib/libm/src/s_catan.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Complex circular arc tangent
 *
 *
 * SYNOPSIS:
 *
 * double complex catan();
 * double complex z, w;
 *
 * w = catan (z);
 *
 *
 * DESCRIPTION:
 *
 * If
 *     z = x + iy,
 *
 * then
 *          1       (    2x     )
 * Re w  =  - arctan(-----------)  +  k PI
 *          2       (     2    2)
 *                  (1 - x  - y )
 *
 *               ( 2         2)
 *          1    (x  +  (y+1) )
 * Im w  =  - log(------------)
 *          4    ( 2         2)
 *               (x  +  (y-1) )
 *
 * Where k is an arbitrary integer.
 *
 * catan(z) = -i catanh(iz).
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    DEC       -10,+10      5900       1.3e-16     7.8e-18
 *    IEEE      -10,+10     30000       2.3e-15     8.5e-17
 * The check catan( ctan(z) )  =  z, with |x| and |y| < PI/2,
 * had peak relative error 1.5e-16, rms relative error
 * 2.9e-17.  See also clog().
 */

/* the multiple */


=== system/lib/libc/musl/src/complex/catanf.c ===
SHA256: 2dbd38c8d786140372a04bfde641a9e290a842fe29133d3d0cd9f629170b9fc7
Primary Git blob: 1d569f2dacf99b075d8b205e874383c2c41c9212
/* origin: OpenBSD /usr/src/lib/libm/src/s_catanf.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Complex circular arc tangent
 *
 *
 * SYNOPSIS:
 *
 * float complex catanf();
 * float complex z, w;
 *
 * w = catanf( z );
 *
 *
 * DESCRIPTION:
 *
 * If
 *     z = x + iy,
 *
 * then
 *          1       (    2x     )
 * Re w  =  - arctan(-----------)  +  k PI
 *          2       (     2    2)
 *                  (1 - x  - y )
 *
 *               ( 2         2)
 *          1    (x  +  (y+1) )
 * Im w  =  - log(------------)
 *          4    ( 2         2)
 *               (x  +  (y-1) )
 *
 * Where k is an arbitrary integer.
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      -10,+10     30000        2.3e-6      5.2e-8
 */

/* the multiple */


=== system/lib/libc/musl/src/complex/catanh.c ===
SHA256: ee35815141c85bd3b28c65bffbe38176966002a088acac494934f517c9e283b0
Primary Git blob: c324c7f2bca8017d6e27474a21576c157cf78ad9
/* atanh = -i atan(i z) */


=== system/lib/libc/musl/src/complex/catanl.c ===
SHA256: 3857a0a047869d9219421a12a4ada0f384e9fbe7c21b3c9516622852f475cf1a
Primary Git blob: e62526c00672b42b91592334b2f113326c40e9a7
/* origin: OpenBSD /usr/src/lib/libm/src/s_catanl.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Complex circular arc tangent
 *
 *
 * SYNOPSIS:
 *
 * long double complex catanl();
 * long double complex z, w;
 *
 * w = catanl( z );
 *
 *
 * DESCRIPTION:
 *
 * If
 *     z = x + iy,
 *
 * then
 *          1       (    2x     )
 * Re w  =  - arctan(-----------)  +  k PI
 *          2       (     2    2)
 *                  (1 - x  - y )
 *
 *               ( 2         2)
 *          1    (x  +  (y+1) )
 * Im w  =  - log(------------)
 *          4    ( 2         2)
 *               (x  +  (y-1) )
 *
 * Where k is an arbitrary integer.
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    DEC       -10,+10      5900       1.3e-16     7.8e-18
 *    IEEE      -10,+10     30000       2.3e-15     8.5e-17
 * The check catan( ctan(z) )  =  z, with |x| and |y| < PI/2,
 * had peak relative error 1.5e-16, rms relative error
 * 2.9e-17.  See also clog().
 */

/* the multiple */


=== system/lib/libc/musl/src/complex/ccos.c ===
SHA256: 5cb0e3cf6387fedaf96ed4b9bb364ce34b5f97722440d08f75549e04b4edcca2
Primary Git blob: f32e1fadfbf3439f0d804013f2235bf4bf2497a0
/* cos(z) = cosh(i z) */


=== system/lib/libc/musl/src/complex/ccosh.c ===
SHA256: 9997abb272468781bc9b6b61a1550e95d1f956df109e0a646d578a3dc2c3aef9
Primary Git blob: c995da7bb2247a88db849199d1d5aea12bec8b30
/* origin: FreeBSD /usr/src/lib/msun/src/s_ccosh.c */

/*-
 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Hyperbolic cosine of a complex argument z = x + i y.
 *
 * cosh(z) = cosh(x+iy)
 *         = cosh(x) cos(y) + i sinh(x) sin(y).
 *
 * Exceptional values are noted in the comments within the source code.
 * These values and the return value were taken from n1124.pdf.
 */

/* Handle the nearly-non-exceptional cases where x and y are finite. */

/* small x: normal case */

/* |x| >= 22, so cosh(x) ~= exp(|x|) */

/* x < 710: exp(|x|) won't overflow */

/* x < 1455: scale to avoid overflow */

/* x >= 1455: the result always overflows */

/*
	 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0.
	 * The sign of 0 in the result is unspecified.  Choice = normally
	 * the same as dNaN.  Raise the invalid floating-point exception.
	 *
	 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0.
	 * The sign of 0 in the result is unspecified.  Choice = normally
	 * the same as d(NaN).
	 */

/*
	 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0.
	 *
	 * cosh(NaN +- I 0)   = d(NaN) + I sign(d(NaN, +-0))0.
	 * The sign of 0 in the result is unspecified.
	 */

/*
	 * cosh(x +- I Inf) = dNaN + I dNaN.
	 * Raise the invalid floating-point exception for finite nonzero x.
	 *
	 * cosh(x + I NaN) = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception for finite
	 * nonzero x.  Choice = don't raise (except for signaling NaNs).
	 */

/*
	 * cosh(+-Inf + I NaN)  = +Inf + I d(NaN).
	 *
	 * cosh(+-Inf +- I Inf) = +Inf + I dNaN.
	 * The sign of Inf in the result is unspecified.  Choice = always +.
	 * Raise the invalid floating-point exception.
	 *
	 * cosh(+-Inf + I y)   = +Inf cos(y) +- I Inf sin(y)
	 */

/*
	 * cosh(NaN + I NaN)  = d(NaN) + I d(NaN).
	 *
	 * cosh(NaN +- I Inf) = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception.
	 * Choice = raise.
	 *
	 * cosh(NaN + I y)    = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception for finite
	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
	 */


=== system/lib/libc/musl/src/complex/ccoshf.c ===
SHA256: 6ebf4355682268356685ba79621a47f2f955ca910bf13ca6ed32bb52e893574f
Primary Git blob: 189ce946dd4765ef47cffc897daa24268c486a32
/* origin: FreeBSD /usr/src/lib/msun/src/s_ccoshf.c */

/*-
 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Hyperbolic cosine of a complex argument.  See s_ccosh.c for details.
 */

/* small x: normal case */

/* |x| >= 9, so cosh(x) ~= exp(|x|) */

/* x < 88.7: expf(|x|) won't overflow */

/* x < 192.7: scale to avoid overflow */

/* x >= 192.7: the result always overflows */


=== system/lib/libc/musl/src/complex/ccoshl.c ===
SHA256: ea721dbeaacc27dcf712ef59dcc41008046a6aaeb17d45d4290b947a393d7d37
Primary Git blob: ffb4d8a1465f47c1a5ac04d8c9005599fd231416
//FIXME


=== system/lib/libc/musl/src/complex/cexp.c ===
SHA256: 30943458b19d417812e326d8a61a2413ebce139c826c997ad6598dcddb6e673d
Primary Git blob: 7fb489bb930c4b3ae6095534052cc17927ad2aa5
/* origin: FreeBSD /usr/src/lib/msun/src/s_cexp.c */

/*-
 * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* high bits of MAX_EXP * ln2 ~= 710 */

/* (MAX_EXP - MIN_DENORM_EXP) * ln2 */

/* cexp(x + I 0) = exp(x) + I 0 */

/* cexp(0 + I y) = cos(y) + I sin(y) */

/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */

/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */

/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */

/*
		 * x is between 709.7 and 1454.3, so we must scale to avoid
		 * overflow in exp(x).
		 */

/*
		 * Cases covered here:
		 *  -  x < exp_ovfl and exp(x) won't overflow (common case)
		 *  -  x > cexp_ovfl, so exp(x) * s overflows for all s > 0
		 *  -  x = +-Inf (generated by exp())
		 *  -  x = NaN (spurious inexact exception from y)
		 */


=== system/lib/libc/musl/src/complex/cexpf.c ===
SHA256: 7de06c6bebd823987c5eefe19821b8a473332ec724d6cc0a6a27955a33ba3734
Primary Git blob: 00d258f3fcea4e3b363cee35bf1be9058681ebc9
/* origin: FreeBSD /usr/src/lib/msun/src/s_cexpf.c */

/*-
 * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* MAX_EXP * ln2 ~= 88.722839355 */

/* (MAX_EXP - MIN_DENORM_EXP) * ln2 */

/* cexp(x + I 0) = exp(x) + I 0 */

/* cexp(0 + I y) = cos(y) + I sin(y) */

/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */

/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */

/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */

/*
		 * x is between 88.7 and 192, so we must scale to avoid
		 * overflow in expf(x).
		 */

/*
		 * Cases covered here:
		 *  -  x < exp_ovfl and exp(x) won't overflow (common case)
		 *  -  x > cexp_ovfl, so exp(x) * s overflows for all s > 0
		 *  -  x = +-Inf (generated by exp())
		 *  -  x = NaN (spurious inexact exception from y)
		 */


=== system/lib/libc/musl/src/complex/cexpl.c ===
SHA256: 33d80da45c1620cc545192039e77dc24b8c5e9b3529b26dc3370025dd6fc9364
Primary Git blob: d4df950e335cbb25c71a49147a8b9a22d26219ac
//FIXME


=== system/lib/libc/musl/src/complex/clog.c ===
SHA256: 31d39749e4a35bfcd155727be82f093b0d82cb150f6036921a6c336ce5213389
Primary Git blob: b587c2915a002c2a32222bba5cbc170c3dd526bb
// FIXME

/* log(z) = log(|z|) + i arg(z) */


=== system/lib/libc/musl/src/complex/clogf.c ===
SHA256: 26e345b2ab6a02a239c82119d3c45d4dc8d272cc0dcd8dcc0c81f5bccd298e2a
Primary Git blob: 0389d4723082b4583db00cd7b7abcb67faec9f98
// FIXME


=== system/lib/libc/musl/src/complex/clogl.c ===
SHA256: 3dc4312e175401657800add8a4394b95d5cf252244e586edbf79cf0128328cb0
Primary Git blob: 88e83e87c92593f85a8cbe370066955d36d922f0
// FIXME


=== system/lib/libc/musl/src/complex/cpow.c ===
SHA256: 806e7dbb2cae7f15d3d8d7a9d658b14accda94e1f290f1e7477b719ebac96b27
Primary Git blob: 1137d3911724ced602aceb54cc1b7fff2ee5badb
/* pow(z, c) = exp(c log(z)), See C99 G.6.4.1 */


=== system/lib/libc/musl/src/complex/csin.c ===
SHA256: 179640769b92bbb1975bff452eea3259513a14d0640dacd9734ac62017748002
Primary Git blob: 535c4bf8b0b0cd4432563fc54d49f050c92270b3
/* sin(z) = -i sinh(i z) */


=== system/lib/libc/musl/src/complex/csinh.c ===
SHA256: ed236ed0232c73d39a372a6799ba63b2eaeccc5f03aca0045fcb1504bb489489
Primary Git blob: eda0ab59f445d4135ba71336c0898f3eafa7102e
/* origin: FreeBSD /usr/src/lib/msun/src/s_csinh.c */

/*-
 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Hyperbolic sine of a complex argument z = x + i y.
 *
 * sinh(z) = sinh(x+iy)
 *         = sinh(x) cos(y) + i cosh(x) sin(y).
 *
 * Exceptional values are noted in the comments within the source code.
 * These values and the return value were taken from n1124.pdf.
 */

/* Handle the nearly-non-exceptional cases where x and y are finite. */

/* small x: normal case */

/* |x| >= 22, so cosh(x) ~= exp(|x|) */

/* x < 710: exp(|x|) won't overflow */

/* x < 1455: scale to avoid overflow */

/* x >= 1455: the result always overflows */

/*
	 * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN.
	 * The sign of 0 in the result is unspecified.  Choice = normally
	 * the same as dNaN.  Raise the invalid floating-point exception.
	 *
	 * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN).
	 * The sign of 0 in the result is unspecified.  Choice = normally
	 * the same as d(NaN).
	 */

/*
	 * sinh(+-Inf +- I 0) = +-Inf + I +-0.
	 *
	 * sinh(NaN +- I 0)   = d(NaN) + I +-0.
	 */

/*
	 * sinh(x +- I Inf) = dNaN + I dNaN.
	 * Raise the invalid floating-point exception for finite nonzero x.
	 *
	 * sinh(x + I NaN) = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception for finite
	 * nonzero x.  Choice = don't raise (except for signaling NaNs).
	 */

/*
	 * sinh(+-Inf + I NaN)  = +-Inf + I d(NaN).
	 * The sign of Inf in the result is unspecified.  Choice = normally
	 * the same as d(NaN).
	 *
	 * sinh(+-Inf +- I Inf) = +Inf + I dNaN.
	 * The sign of Inf in the result is unspecified.  Choice = always +.
	 * Raise the invalid floating-point exception.
	 *
	 * sinh(+-Inf + I y)   = +-Inf cos(y) + I Inf sin(y)
	 */

/*
	 * sinh(NaN + I NaN)  = d(NaN) + I d(NaN).
	 *
	 * sinh(NaN +- I Inf) = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception.
	 * Choice = raise.
	 *
	 * sinh(NaN + I y)    = d(NaN) + I d(NaN).
	 * Optionally raises the invalid floating-point exception for finite
	 * nonzero y.  Choice = don't raise (except for signaling NaNs).
	 */


=== system/lib/libc/musl/src/complex/csinhf.c ===
SHA256: 4ed3be03188b48d701d8edaa88b0e282cb2ec88b8af1c2f0e2a3f76fba60a773
Primary Git blob: eb1d98c524a7d3db59eb4fccbf06498bca279721
/* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */

/*-
 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Hyperbolic sine of a complex argument z.  See s_csinh.c for details.
 */

/* small x: normal case */

/* |x| >= 9, so cosh(x) ~= exp(|x|) */

/* x < 88.7: expf(|x|) won't overflow */

/* x < 192.7: scale to avoid overflow */

/* x >= 192.7: the result always overflows */


=== system/lib/libc/musl/src/complex/csinhl.c ===
SHA256: 501fd7e0313f58de43a0bc0d57e90a0c38fb9c2d0be64cf4b75513fa429cf5da
Primary Git blob: 09fd18f931126203169cb1dc6ec12d6f19ad9bfa
//FIXME


=== system/lib/libc/musl/src/complex/csqrt.c ===
SHA256: 4f6cfa6aec61754c1ee2ea683ec00e7837eaa1993edafbc516c6c4978e3567b4
Primary Git blob: c36de00196cfe105bc236c85a426a3e65004d654
/* origin: FreeBSD /usr/src/lib/msun/src/s_csqrt.c */

/*-
 * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * gcc doesn't implement complex multiplication or division correctly,
 * so we need to handle infinities specially. We turn on this pragma to
 * notify conforming c99 compilers that the fast-but-incorrect code that
 * gcc generates is acceptable, since the special cases have already been
 * handled.
 */

/* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */

/* Handle special cases. */

/* raise invalid if b is not a NaN */

/* return NaN + NaN i */

/*
		 * csqrt(inf + NaN i)  = inf +  NaN i
		 * csqrt(inf + y i)    = inf +  0 i
		 * csqrt(-inf + NaN i) = NaN +- inf i
		 * csqrt(-inf + y i)   = 0   +  inf i
		 */

/*
	 * The remaining special case (b is NaN) is handled just fine by
	 * the normal code path below.
	 */

/* Scale to avoid overflow. */

/* Algorithm 312, CACM vol 10, Oct 1967. */

/* Rescale. */


=== system/lib/libc/musl/src/complex/csqrtf.c ===
SHA256: 8dd69a3ec2052cf54f38e61156b057c2ff74d00da9db64da63f646e30a36e8e3
Primary Git blob: a6163974da042e1a1ba3b12836043175f2eb1331
/* origin: FreeBSD /usr/src/lib/msun/src/s_csqrtf.c */

/*-
 * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * gcc doesn't implement complex multiplication or division correctly,
 * so we need to handle infinities specially. We turn on this pragma to
 * notify conforming c99 compilers that the fast-but-incorrect code that
 * gcc generates is acceptable, since the special cases have already been
 * handled.
 */

/* Handle special cases. */

/* raise invalid if b is not a NaN */

/* return NaN + NaN i */

/*
		 * csqrtf(inf + NaN i)  = inf +  NaN i
		 * csqrtf(inf + y i)    = inf +  0 i
		 * csqrtf(-inf + NaN i) = NaN +- inf i
		 * csqrtf(-inf + y i)   = 0   +  inf i
		 */

/*
	 * The remaining special case (b is NaN) is handled just fine by
	 * the normal code path below.
	 */

/*
	 * We compute t in double precision to avoid overflow and to
	 * provide correct rounding in nearly all cases.
	 * This is Algorithm 312, CACM vol 10, Oct 1967.
	 */


=== system/lib/libc/musl/src/complex/csqrtl.c ===
SHA256: 7dfdf3fa8ac3497d470ec1dbaf897437e75e5ec40162a15cb319ab318cf7f267
Primary Git blob: 225393790420d67b9b5740d9f73e756912b59bfb
//FIXME


=== system/lib/libc/musl/src/complex/ctan.c ===
SHA256: e07dae94234591effaa0c5601da4c13999418fec12bf01c0f2fa20bbf0785fa1
Primary Git blob: 918717bfcc42233dfdb83493002ea4ca187bde93
/* tan(z) = -i tanh(i z) */


=== system/lib/libc/musl/src/complex/ctanh.c ===
SHA256: 7daa31e0831e9805934bd0e6a33816daf16c0bf1076babeb9799fe6e185ac045
Primary Git blob: 54004cd7dcd97d64ff377022745f45416d9e4bf6
/* origin: FreeBSD /usr/src/lib/msun/src/s_ctanh.c */

/*-
 * Copyright (c) 2011 David Schultz
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Hyperbolic tangent of a complex argument z = x + i y.
 *
 * The algorithm is from:
 *
 *   W. Kahan.  Branch Cuts for Complex Elementary Functions or Much
 *   Ado About Nothing's Sign Bit.  In The State of the Art in
 *   Numerical Analysis, pp. 165 ff.  Iserles and Powell, eds., 1987.
 *
 * Method:
 *
 *   Let t    = tan(x)
 *       beta = 1/cos^2(y)
 *       s    = sinh(x)
 *       rho  = cosh(x)
 *
 *   We have:
 *
 *   tanh(z) = sinh(z) / cosh(z)
 *
 *             sinh(x) cos(y) + i cosh(x) sin(y)
 *           = ---------------------------------
 *             cosh(x) cos(y) + i sinh(x) sin(y)
 *
 *             cosh(x) sinh(x) / cos^2(y) + i tan(y)
 *           = -------------------------------------
 *                    1 + sinh^2(x) / cos^2(y)
 *
 *             beta rho s + i t
 *           = ----------------
 *               1 + beta s^2
 *
 * Modifications:
 *
 *   I omitted the original algorithm's handling of overflow in tan(x) after
 *   verifying with nearpi.c that this can't happen in IEEE single or double
 *   precision.  I also handle large x differently.
 */

/*
	 * ctanh(NaN + i 0) = NaN + i 0
	 *
	 * ctanh(NaN + i y) = NaN + i NaN               for y != 0
	 *
	 * The imaginary part has the sign of x*sin(2*y), but there's no
	 * special effort to get this right.
	 *
	 * ctanh(+-Inf +- i Inf) = +-1 +- 0
	 *
	 * ctanh(+-Inf + i y) = +-1 + 0 sin(2y)         for y finite
	 *
	 * The imaginary part of the sign is unspecified.  This special
	 * case is only needed to avoid a spurious invalid exception when
	 * y is infinite.
	 */

/* x is NaN */

/* x = copysign(1, x) */

/*
	 * ctanh(+-0 + i NAN) = +-0 + i NaN
	 * ctanh(+-0 +- i Inf) = +-0 + i NaN
	 * ctanh(x + i NAN) = NaN + i NaN
	 * ctanh(x +- i Inf) = NaN + i NaN
	 */

/*
	 * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the
	 * approximation sinh^2(huge) ~= exp(2*huge) / 4.
	 * We use a modified formula to avoid spurious overflow.
	 */

/* x >= 22 */

/* Kahan's algorithm */

/* = 1 / cos^2(y) */

/* = cosh(x) */


=== system/lib/libc/musl/src/complex/ctanhf.c ===
SHA256: 1ebb7bddc872c96bf3e7c8d1a529c14f28db4cf75cc8237fdb1ad62764b405bf
Primary Git blob: 7f422ba7fd3a583fc4062575d625503839d0291d
/* origin: FreeBSD /usr/src/lib/msun/src/s_ctanhf.c */

/*-
 * Copyright (c) 2011 David Schultz
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * Hyperbolic tangent of a complex argument z.  See s_ctanh.c for details.
 */

/* x >= 11 */


=== system/lib/libc/musl/src/complex/ctanhl.c ===
SHA256: 570fc5ffdcc132efd24373704d7a434d561fccf95075837c86654bfb31355b8e
Primary Git blob: 45d5862c8baca5d8586e9681cf10cf499432b668
//FIXME


=== system/lib/libc/musl/src/conf/confstr.c ===
SHA256: ccd2eba42ef2a22ad676716ce417c5ab0415217b85238a6e830310630e7e7694
Primary Git blob: 9c12d365babf23412f5bb157af9f70c100e01a2f
// TODO(sbc): Can we just remove these custom values.

// We have tests that check for them but its not clear

// anything else does.

// snprintf is overkill but avoid wasting code size to implement

// this completely useless function and its truncation semantics


=== system/lib/libc/musl/src/conf/fpathconf.c ===
SHA256: 19e987cf0ae74c7eea61de3d44a93c7e083a3842b5a372696165d90004940727
Primary Git blob: 3161c76ffcab40881b3c7f28bcf7031b8bcb3405
// XXX EMSCRIPTEN replace -1


=== system/lib/libc/musl/src/conf/sysconf.c ===
SHA256: 9317b5b69e588960917699d718acd1350466cb9d67ebde36bc6b972433128b2f
Primary Git blob: c300a834c1248c76f517e7d0b2bb6c122d7827c5
// XXX EMSCRIPTEN replace RLIM(NPROC),

// XXX EMSCRIPTEN replace RLIM(NOFILE),

/* ?? */

// XXX EMSCRIPTEN replace VER,


=== system/lib/libc/musl/src/crypt/crypt.c ===
SHA256: 9b69ea0289cdb04779b017d99f80eabc89c162f3cf433fddf88c985765ba0cc6
Primary Git blob: e6237e397fc757074907fb1684c5cfa14d5083c1
/* This buffer is sufficiently large for all
	 * currently-supported hash types. It needs to be updated if
	 * longer hashes are added. The cast to struct crypt_data * is
	 * purely to meet the public API requirements of the crypt_r
	 * function; the implementation of crypt_r uses the object
	 * purely as a char buffer. */


=== system/lib/libc/musl/src/crypt/crypt_blowfish.c ===
SHA256: 0f9054739e295e3e981e7aa29c8f287a190aef065b84a82a4c6817120d5da05d
Primary Git blob: d722607b02290fc37018bdb4e39be492fe57c2a5
/* Modified by Rich Felker in for inclusion in musl libc, based on
 * Solar Designer's second size-optimized version sent to the musl
 * mailing list. */

/*
 * The crypt_blowfish homepage is:
 *
 *	http://www.openwall.com/crypt/
 *
 * This code comes from John the Ripper password cracker, with reentrant
 * and crypt(3) interfaces added, but optimizations specific to password
 * cracking removed.
 *
 * Written by Solar Designer <solar at openwall.com> in 1998-2012.
 * No copyright is claimed, and the software is hereby placed in the public
 * domain.  In case this attempt to disclaim copyright and place the software
 * in the public domain is deemed null and void, then the software is
 * Copyright (c) 1998-2014 Solar Designer and it is hereby released to the
 * general public under the following terms:
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted.
 *
 * There's ABSOLUTELY NO WARRANTY, express or implied.
 *
 * It is my intent that you should be able to use this on your system,
 * as part of a software package, or anywhere else to improve security,
 * ensure compatibility, or for any other purpose.  I would appreciate
 * it if you give credit where it is due and keep your modifications in
 * the public domain as well, but I don't require that in order to let
 * you place this code and any modifications you make under a license
 * of your choice.
 *
 * This implementation is fully compatible with OpenBSD's bcrypt.c for prefix
 * "$2b$", originally by Niels Provos <provos at citi.umich.edu>, and it uses
 * some of his ideas.  The password hashing algorithm was designed by David
 * Mazieres <dm at lcs.mit.edu>.  For information on the level of
 * compatibility for bcrypt hash prefixes other than "$2b$", please refer to
 * the comments in BF_set_key() below and to the included crypt(3) man page.
 *
 * There's a paper on the algorithm that explains its design decisions:
 *
 *	http://www.usenix.org/events/usenix99/provos.html
 *
 * Some of the tricks in BF_ROUND might be inspired by Eric Young's
 * Blowfish library (I can't be sure if I would think of something if I
 * hadn't seen his code).
 */

/* Number of Blowfish rounds, this is also hardcoded into a few places */

/*
 * Magic IV for 64 Blowfish encryptions that we do at the end.
 * The string is "OrpheanBeholderScryDoubt" on big-endian.
 */

/*
 * P-box and S-box tables initialized with digits of Pi.
 */

/*
 * There was a sign extension bug in older revisions of this function.  While
 * we would have liked to simply fix the bug and move on, we have to provide
 * a backwards compatibility feature (essentially the bug) for some systems and
 * a safety measure for some others.  The latter is needed because for certain
 * multiple inputs to the buggy algorithm there exist easily found inputs to
 * the correct algorithm that produce the same hash.  Thus, we optionally
 * deviate from the correct algorithm just enough to avoid such collisions.
 * While the bug itself affected the majority of passwords containing
 * characters with the 8th bit set (although only a percentage of those in a
 * collision-producing way), the anti-collision safety measure affects
 * only a subset of passwords containing the '\xff' character (not even all of
 * those passwords, just some of them).  This character is not found in valid
 * UTF-8 sequences and is rarely used in popular 8-bit character encodings.
 * Thus, the safety measure is unlikely to cause much annoyance, and is a
 * reasonable tradeoff to use when authenticating against existing hashes that
 * are not reliably known to have been computed with the correct algorithm.
 *
 * We use an approach that tries to minimize side-channel leaks of password
 * information - that is, we mostly use fixed-cost bitwise operations instead
 * of branches or table lookups.  (One conditional branch based on password
 * length remains.  It is not part of the bug aftermath, though, and is
 * difficult and possibly unreasonable to avoid given the use of C strings by
 * the caller, which results in similar timing leaks anyway.)
 *
 * For actual implementation, we set an array index in the variable "bug"
 * (0 means no bug, 1 means sign extension bug emulation) and a flag in the
 * variable "safety" (bit 16 is set when the safety measure is requested).
 * Valid combinations of settings are:
 *
 * Prefix "$2a$": bug = 0, safety = 0x10000
 * Prefix "$2b$": bug = 0, safety = 0
 * Prefix "$2x$": bug = 1, safety = 0
 * Prefix "$2y$": bug = 0, safety = 0
 */

/* correct */

/* bug */

/*
 * Sign extension in the first char has no effect - nothing to overwrite yet,
 * and those extra 24 bits will be fully shifted out of the 32-bit word.  For
 * chars 2, 3, 4 in each four-char block, we set bit 7 of "sign" if sign
 * extension in tmp[1] occurs.  Once this flag is set, it remains set.
 */

/* Non-zero on any differences */

/*
 * At this point, "diff" is zero iff the correct and buggy algorithms produced
 * exactly the same result.  If so and if "sign" is non-zero, which indicates
 * that there was a non-benign sign extension, this means that we have a
 * collision between the correctly computed hash for this password and a set of
 * passwords that could be supplied to the buggy algorithm.  Our safety measure
 * is meant to protect from such many-buggy to one-correct collisions, by
 * deviating from the correct algorithm in such cases.  Let's check for this.
 */

/* still zero iff exact match */

/* ditto */

/* bit 16 set iff "diff" was non-zero (on non-match) */

/* move the non-benign sign extension flag to bit 16 */

/* action needed? */

/*
 * If we have determined that we need to deviate from the correct algorithm,
 * flip bit 16 in initial expanded key.  (The choice of 16 is arbitrary, but
 * let's stick to it now.  It came out of the approach we used above, and it's
 * not any worse than any other choice we could make.)
 *
 * It is crucial that we don't do the same to the expanded key used in the main
 * Eksblowfish loop.  By doing it to only one of these two, we deviate from a
 * state that could be directly specified by a password to the buggy algorithm
 * (and to the fully correct one as well, but that's a side-effect).
 */

/* This has to be bug-compatible with the original implementation, so
 * only encode 23 of the 24 bytes. :-) */

/*
 * Please preserve the runtime self-test.  It serves two purposes at once:
 *
 * 1. We really can't afford the risk of producing incompatible hashes e.g.
 * when there's something like gcc bug 26587 again, whereas an application or
 * library integrating this code might not also integrate our external tests or
 * it might not run them after every build.  Even if it does, the miscompile
 * might only occur on the production build, but not on a testing build (such
 * as because of different optimization settings).  It is painful to recover
 * from incorrectly-computed hashes - merely fixing whatever broke is not
 * enough.  Thus, a proactive measure like this self-test is needed.
 *
 * 2. We don't want to leave sensitive data from our actual password hash
 * computation on the stack or in registers.  Previous revisions of the code
 * would do explicit cleanups, but simply running the self-test after hash
 * computation is more reliable.
 *
 * The performance cost of this quick self-test is around 0.6% at the "$2a$08"
 * setting.
 */

/* 'a', 'b', 'y' */

/* 'x' */

/* Hash the supplied password */

/*
 * Do a quick self-test.  It is important that we make both calls to BF_crypt()
 * from the same scope such that they likely use the same stack locations,
 * which makes the second call overwrite the first call's sensitive data on the
 * stack and makes it more likely that any alignment related issues would be
 * detected by the self-test.
 */

/* $2a$ */

/* $2y$ */

/* undo the safety (for comparison) */


=== system/lib/libc/musl/src/crypt/crypt_des.c ===
SHA256: 546b4ee35446fb2a551d7414779395789f81d53aefbabd8914375686af5d228e
Primary Git blob: 338a8f3715f2da6d925ce2fb6fd741fcf49e9656
/*
 * This version has been further modified by Rich Felker, primary author
 * and maintainer of musl libc, to remove table generation code and
 * replaced all runtime-generated constant tables with static-initialized
 * tables in the binary, in the interest of minimizing non-shareable
 * memory usage and stack size requirements.
 */

/*
 * This version is derived from the original implementation of FreeSec
 * (release 1.1) by David Burren.  I've made it reentrant, reduced its memory
 * usage from about 70 KB to about 7 KB (with only minimal performance impact
 * and keeping code size about the same), made the handling of invalid salts
 * mostly UFC-crypt compatible, added a quick runtime self-test (which also
 * serves to zeroize the stack from sensitive data), and added optional tests.
 * - Solar Designer <solar at openwall.com>
 */

/*
 * FreeSec: libcrypt for NetBSD
 *
 * Copyright (c) 1994 David Burren
 * Copyright (c) 2000,2002,2010,2012 Solar Designer
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the author nor the names of other contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	$Owl: Owl/packages/glibc/crypt_freesec.c,v 1.6 2010/02/20 14:45:06 solar Exp $
 *	$Id: crypt.c,v 1.15 1994/09/13 04:58:49 davidb Exp $
 *
 * This is an original implementation of the DES and the crypt(3) interfaces
 * by David Burren.  It has been heavily re-worked by Solar Designer.
 */

/*   0000000000111111111122222222223333333333444444444455555555556666 */

/*   0123456789012345678901234567890123456789012345678901234567890123 */

/*
 * We match the behavior of UFC-crypt on systems where "char" is signed by
 * default (the majority), regardless of char's signedness on our system.
 */

/*
 * When we choose to "support" invalid salts, nevertheless disallow those
 * containing characters that would violate the passwd file format.
 */

/*
	 * Do key permutation and split into two 28-bit subkeys.
	 */

/*
	 * Rotate subkeys and do compression permutation.
	 */

/*
 * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format.
 */

/*
	 * Do initial permutation (IP).
	 */

/*
		 * Do each round.
		 */

/*
			 * Expand R to 48 bits (simulate the E-box).
			 */

/*
			 * Do salting for crypt() and friends, and
			 * XOR with the permuted key.
			 */

/*
			 * Do S-box lookups (which shrink it back to 32 bits)
			 * and do the P-box permutation at the same time.
			 */

/*
			 * Now that we've permuted things, complete f().
			 */

/*
	 * Do final permutation (inverse of IP).
	 */

/*
	 * Copy the key, shifting each character left by one bit and padding
	 * with zeroes.
	 */

/*
		 * "new"-style:
		 *	setting - underscore, 4 chars of count, 4 chars of salt
		 *	key - unlimited characters
		 */

/*
			 * Encrypt the key with itself.
			 */

/*
			 * And XOR with the next 8 characters of the key.
			 */

/*
		 * "old"-style:
		 *	setting - 2 chars of salt
		 *	key - up to 8 characters
		 */

/*
	 * Do it.
	 */

/*
	 * Now encode the result...
	 */

/*
	 * Hash the supplied password.
	 */

/*
	 * Perform a quick self-test.  It is important that we make both calls
	 * to _crypt_extended_r_uut() from the same scope such that they likely
	 * use the same stack locations, which makes the second call overwrite
	 * the first call's sensitive data on the stack and makes it more
	 * likely that any alignment related issues would be detected.
	 */


=== system/lib/libc/musl/src/crypt/crypt_md5.c ===
SHA256: 85d1d364c100fc982e99adb0d176e1d4475d175fc5c12bba696cda9c62d62c6b
Primary Git blob: 6e75b36cbd6b981940089480630f1fec68183fa7
/*
 * md5 crypt implementation
 *
 * original md5 crypt design is from Poul-Henning Kamp
 * this implementation was created based on the code in freebsd
 * at least 32bit int is assumed, key is limited and $1$ prefix is mandatory,
 * on error "*" is returned
 */

/* public domain md5 implementation based on rfc1321 and libtomcrypt */

/* processed message length */

/* hash state */

/* message block buffer */

/*-
 * Copyright (c) 2003 Poul-Henning Kamp
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* key limit is not part of the original design, added for DoS protection */

/* reject large keys */

/* setting: $1$salt$ (closing $ is optional) */

/* md5(key salt key) */

/* md5(key $1$ salt repeated-md weird-key[0]-0) */

/* md = f(md, key, salt) iteration */

/* output is $1$salt$hash */

/* self test and stack cleanup */


=== system/lib/libc/musl/src/crypt/crypt_r.c ===
SHA256: 22c953e917c28f59608493913f3f132dc9343baff228ff198dbee197e39ad143
Primary Git blob: db6015e236f639089cb1b6c4cc65f548b96b56ed
/* Per the crypt_r API, the caller has provided a pointer to
	 * struct crypt_data; however, this implementation does not
	 * use the structure to store any internal state, and treats
	 * it purely as a char buffer for storing the result. */


=== system/lib/libc/musl/src/crypt/crypt_sha256.c ===
SHA256: 26f3ae83a89a52640f3979df81eb50a431e75c83d5c18f1487325a39ee84fb73
Primary Git blob: e885dc68e3c5b7260c0d1aace28872f837bf4322
/*
 * public domain sha256 crypt implementation
 *
 * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt
 * in this implementation at least 32bit int is assumed,
 * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is rejected
 * in the salt and rounds= setting must contain a valid iteration count,
 * on error "*" is returned.
 */

/* public domain sha256 implementation based on fips180-3 */

/* processed message length */

/* hash state */

/* message block buffer */

/* key limit is not part of the original design, added for DoS protection.
 * rounds limit has been lowered (versus the reference/spec), also for DoS
 * protection. runtime is O(klen^2 + klen*rounds) */

/* hash n bytes of the repeated md message digest */

/* reject large keys */

/* setting: $5$rounds=n$salt$ (rounds=n$ and closing $ are optional) */

/*
		 * this is a deviation from the reference:
		 * bad rounds setting is rejected if it is
		 * - empty
		 * - unterminated (missing '$')
		 * - begins with anything but a decimal digit
		 * the reference implementation treats these bad
		 * rounds as part of the salt or parse them with
		 * strtoul semantics which may cause problems
		 * including non-portable hashes that depend on
		 * the host's value of ULONG_MAX.
		 */

/* needed when rounds is zero prefixed or out of bounds */

/* reject characters that interfere with /etc/shadow parsing */

/* B = sha(key salt key) */

/* A = sha(key salt repeat-B alternate-B-key) */

/* DP = sha(repeat-key), this step takes O(klen^2) time */

/* DS = sha(repeat-salt) */

/* iterate A = f(A,DP,DS), this step takes O(rounds*klen) time */

/* output is $5$rounds=n$salt$hash */

/* self test and stack cleanup */


=== system/lib/libc/musl/src/crypt/crypt_sha512.c ===
SHA256: 7148156d195d9bef7eb57a1b2108439679a02372d0fac418004722513bd7b95c
Primary Git blob: 39970cafe87154ddddac5238d2ba3ff2c62859a5
/*
 * public domain sha512 crypt implementation
 *
 * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt
 * in this implementation at least 32bit int is assumed,
 * key length is limited, the $6$ prefix is mandatory, '\n' and ':' is rejected
 * in the salt and rounds= setting must contain a valid iteration count,
 * on error "*" is returned.
 */

/* public domain sha512 implementation based on fips180-3 */

/* >=2^64 bits messages are not supported (about 2000 peta bytes) */

/* processed message length */

/* hash state */

/* message block buffer */

/* key limit is not part of the original design, added for DoS protection.
 * rounds limit has been lowered (versus the reference/spec), also for DoS
 * protection. runtime is O(klen^2 + klen*rounds) */

/* hash n bytes of the repeated md message digest */

/* reject large keys */

/* setting: $6$rounds=n$salt$ (rounds=n$ and closing $ are optional) */

/*
		 * this is a deviation from the reference:
		 * bad rounds setting is rejected if it is
		 * - empty
		 * - unterminated (missing '$')
		 * - begins with anything but a decimal digit
		 * the reference implementation treats these bad
		 * rounds as part of the salt or parse them with
		 * strtoul semantics which may cause problems
		 * including non-portable hashes that depend on
		 * the host's value of ULONG_MAX.
		 */

/* needed when rounds is zero prefixed or out of bounds */

/* reject characters that interfere with /etc/shadow parsing */

/* B = sha(key salt key) */

/* A = sha(key salt repeat-B alternate-B-key) */

/* DP = sha(repeat-key), this step takes O(klen^2) time */

/* DS = sha(repeat-salt) */

/* iterate A = f(A,DP,DS), this step takes O(rounds*klen) time */

/* output is $6$rounds=n$salt$hash */

/* self test and stack cleanup */


=== system/lib/libc/musl/src/ctype/iswctype.c ===
SHA256: eab7d58535088e9ddd250ff246181aa147218d0935723b88faf13e09bada6ca3
Primary Git blob: 71b09b8d24ae56c5cc29bab7053bf2b014e972b7
/* order must match! */


=== system/lib/libc/musl/src/ctype/iswgraph.c ===
SHA256: cde1051bf810063ec4d9c33ec45955c60047ff5919065be748e28989f54b2ed2
Primary Git blob: ecdf466c657f9822de7cc556e97a0931f004982c
/* ISO C defines this function as: */


=== system/lib/libc/musl/src/ctype/iswprint.c ===
SHA256: ae2a5e7411f0f781df42e2a699e863829c6e583bea117a980702622ab227377f
Primary Git blob: 86f9d646ac9e16251120ba09366537da92c102b4
/* Consider all legal codepoints as printable except for:
 * - C0 and C1 control characters
 * - U+2028 and U+2029 (line/para break)
 * - U+FFF9 through U+FFFB (interlinear annotation controls)
 * The following code is optimized heavily to make hot paths for the
 * expected printable characters. */


=== system/lib/libc/musl/src/ctype/iswspace.c ===
SHA256: c8592c0fb5463b314c38926e3df26b9efdfe5f1437958ba20c7c36f81facba80
Primary Git blob: 263afa15c5d746bd5421f5c2271587d2d08f8f28
/* Our definition of whitespace is the Unicode White_Space property,
 * minus non-breaking spaces (U+00A0, U+2007, and U+202F) and script-
 * specific characters with non-blank glyphs (U+1680 and U+180E). */


=== system/lib/libc/musl/src/ctype/toascii.c ===
SHA256: 47c28aebaf1d741ffe347809c828fad7046aadd81e2c69572a227348332904be
Primary Git blob: f0e48e8e91761585db15fbc6a6f2e5fa74496c23
/* nonsense function that should NEVER be used! */


=== system/lib/libc/musl/src/ctype/towctrans.c ===
SHA256: 43f4374b7dfcd24a957b4be4cfa304611e24912529183174ec724fcbaedf82cd
Primary Git blob: 76d137696ee9eb9bfef6607f49ae24779f918dc0
/* lookup entry in two-level base-6 table */

/* use the bit vector out of the tables as an index into
	 * a block-specific set of rules and decode the rule into
	 * a type and a case-mapping delta. */

/* rules 0/1 are simple lower/upper case with a delta.
	 * apply according to desired mapping direction. */

/* binary search. endpoints of the binary search for
	 * this block are stored in the rule delta field. */

/* Hard-coded for the four exceptional titlecase */


=== system/lib/libc/musl/src/dirent/__dirent.h ===
SHA256: 66e394f7f0b6921e15af4f81b6a5f9fd21345b9810272012eed6821e1b1166b3
Primary Git blob: 828a5f178917a97426d4fa35784494d894d25ccc
/* Any changes to this struct must preserve the property:
	 * offsetof(struct __dirent, buf) % sizeof(off_t) == 0 */


=== system/lib/libc/musl/src/env/__environ.c ===
SHA256: 589b03efa51a1b3eed9db297d24beba09a3df39684b34137f2a78e1803b310f8
Primary Git blob: fcc881be0da8b6d84ec9749423b74a5117305a55
// We use emscripten_builtin_malloc here because this memory is never freed and

// and we don't want LSan to consider this a leak.

// construct this before user code

// Ensure null termination.


=== system/lib/libc/musl/src/env/__stack_chk_fail.c ===
SHA256: 9f59ca4d24241fddc32f708433e77644c055a0f72337df7dc4617d2c0561ba53
Primary Git blob: 94d8e1d4c9604fadb7f810ff279cddd951005c9d
/* Sacrifice 8 bits of entropy on 64bit to prevent leaking/
	 * overwriting the canary via string-manipulation functions.
	 * The NULL byte is on the second byte so that off-by-ones can
	 * still be detected. Endianness is taken care of
	 * automatically. */

// Report the reason for the crash, at least in debug builds.

// This is the same message that glibc outputs (even in release builds).


=== system/lib/libc/musl/src/errno/__errno_location.c ===
SHA256: 167fe0721c519c40c6d674db4a3a7c042e54140be230b876024e999660424878
Primary Git blob: 05f55d9eaf7adacbee6f72b79d126a9245ed75be
// For emscripten we use TLS here instead of `__pthread_self`, so that in single

// threaded builds this gets lowered away to normal global variable.


=== system/lib/libc/musl/src/errno/__strerror.h ===
SHA256: 883477158b2466c02b08f4d1c8eec8c1bbf02a3bb2fc80231ff54d1c3d7137d0
Primary Git blob: 598af448c5102b7403ba5b1937e6224905c55770
/* The first entry is a catch-all for codes not enumerated here.
 * This file is included multiple times to declare and define a structure
 * with these messages, and then to define a lookup table translating
 * error codes to offsets of corresponding fields in the structure. */

/* Error handling is introduced to match the behavior in llvm-libc.
 * When invalid errno is specified, Unknown error: errno_code is emitted.
 */

// This is intended to match the errno in llvm-libc.


=== system/lib/libc/musl/src/errno/strerror.c ===
SHA256: f449116b4a268861571b8f1c5e40d3cda09006d49c91ea84007e9be43cfb09d9
Primary Git blob: 0fd1c84289a2ec929f034a74548db9e4b5743300
/* mips has one error code outside of the 8-bit range due to a
 * historical typo, so we just remap it. */

// strerror is a (debug) dependency of many emscripten syscalls which mean it

// must be excluded from LTO, along with all of its dependencies.

// In order to limit the transitive dependencies we disable localization of

// rrno messages here.


=== system/lib/libc/musl/src/exit/abort.c ===
SHA256: dab1cb2741a6890a8d16591457969c6c0d6e7b5fc34d0bf0d663593dee0ee627
Primary Git blob: a6427d51d66e9d6d4ddc6b372d2af30ee56481c0
/* In emscripten we call out to JS to perform the actual abort where it can
	 * produce a nice error.
	 * Note that the JS library function is not called `abort` to avoid conflict
	 * with the JavaScript abort helper (which takes a JS string as an argument
	 * and is itself used to implement `_abort_js`) */

/* If there was a SIGABRT handler installed and it returned, or if
	 * SIGABRT was blocked or ignored, take an AS-safe lock to prevent
	 * sigaction from installing a new SIGABRT handler, uninstall any
	 * handler that may be present, and re-raise the signal to generate
	 * the default action of abnormal termination. */

/* Beyond this point should be unreachable. */


=== system/lib/libc/musl/src/exit/atexit.c ===
SHA256: 0514086a60cb41df4d36e493aa4f4ec4ce034d4620625090b65e31d9a43dd7cc
Primary Git blob: f2401780b30e514c11561d28a8362b4002b59b96
/* Ensure that at least 32 atexit handlers can be registered without malloc */

/* Defer initialization of head so it can be in BSS */

/* If the current function list is full, add a new one */

/* Append function to the list. */

// XXX: EMSCRIPTEN: Use weak aliases here so that we can override these symbols

// in when EXIT_RUNTIME is set to 0.


=== system/lib/libc/musl/src/fcntl/fcntl.c ===
SHA256: b8152b3633125542e6ba6428d9fa6bc585511d7249930c838df913062e328c8d
Primary Git blob: dbc913ba703a50525a675fa61a662748563ab73f
// XXX Emscripten: According to the va_arg man page it is undefined behaviour to

// read arguments that are not passed.  This can lead to a false positive

// in SAFE_HEAP, so avoid it.

// XXX Emscripten: Mirror the behaviour/limitation of glibc which

// will misinterpret negative PIDs in range of -1 to -4095 as being

// errno values.

// CLOEXEC makes no sense for a single process

// CLOEXEC makes no sense for a single process


=== system/lib/libc/musl/src/fcntl/open.c ===
SHA256: 1b3681a3291acd898890b09a94c0fa079be8514100049219f3eacf0edcab5f24
Primary Git blob: b95a90e0172742a802ae8f8d9650cb546af38456
// CLOEXEC makes no sense for a single process


=== system/lib/libc/musl/src/fcntl/posix_fadvise.c ===
SHA256: 363843e99787cdeb79f553c882064c7328355f5905cf044345ac64b8cfb44352
Primary Git blob: 07346d21ae2f1eefe8c987d08c727bedc21bf259
/* Some archs, at least arm and powerpc, have the syscall
	 * arguments reordered to avoid needing 7 argument registers
	 * due to 64-bit argument alignment. */


=== system/lib/libc/musl/src/fenv/fenv.c ===
SHA256: 6994f1dc4cb270072277d61fd3f7836f3df3455c873727a33e59713e0c058d93
Primary Git blob: 5588dad95f428908d7d805dc8b6e1df22970374e
/* Dummy functions for archs lacking fenv implementation */


=== system/lib/libc/musl/src/fenv/fesetround.c ===
SHA256: 977d5b1221c51f14f49b8d210095b61ba0411f7215eaea57aae197df6b6d87af
Primary Git blob: 4e2f164dd5e12d1d866d88e9203c1c1d76f969f6
/* __fesetround wrapper for arch independent argument check */


=== system/lib/libc/musl/src/internal/dynlink.h ===
SHA256: 6a21f9d93893df5f7ef657849627372bf94b816cadae8f43f60507f328675219
Primary Git blob: 55482cf5f7959c516b4984b22a85c09490d6f712
// Declare `struct dso` in this header so that it is visible to gen_struct_info.

// Pointer back to the dlevent in the event sequence which loaded this DSO.

// Flags used to open the library.  We need to cache these so that other

// threads can mirror the open library state.

// Location in memory/table of static data/static function addresses

// The first thread to load a given module alloces the memory and table

// address space and then sets this field to non-zero.

// For DSO load events, where the DSO comes from a file on disc, this

// is a pointer the file data read in by the laoding thread and shared with

// others.

// Flexible array; must be final element of struct

/* These enum constants provide unmatchable default values for
 * any relocation type the arch does not use. */

// __EMSCRIPTEN__


=== system/lib/libc/musl/src/internal/emulate_wait4.c ===
SHA256: 0a23c9821ea56e0d45767a8ea7495e7010bfa035ab4e46247bfae7371267af33
Primary Git blob: f630341212acc1bfc9d9fc8104f777367004b522
/* see ptrace(2); the high bits of si_status can contain */

/* PTRACE_EVENT_ values which must be preserved */


=== system/lib/libc/musl/src/internal/fdpic_crt.h ===
SHA256: 271a3c4d34f9afcd2f47c4bf2f8dbd80d79429b1f18f799e991cbabbba3a13d8
Primary Git blob: 7e9632bb7fcf0dd3de41e829c0b530c809505079
/* If map is a null pointer, the program was loaded by a
	 * non-FDPIC-aware ELF loader, and fixups are not needed,
	 * but the value for the GOT pointer is. */


=== system/lib/libc/musl/src/internal/floatscan.c ===
SHA256: 13a007ee0be8682efa12c80e088a1758a425d8be1842980609f20c0f9d6d9ad5
Primary Git blob: 8c0828fcb39e6e0e742309913eef1aa955e582e5
/* Don't let leading zeros consume buffer space */

/* Handle zero specially to avoid nasty special cases later */

/* Optimize small integers (w/no exponent) and over/under-flow */

/* Align incomplete final B1B digit */

/* Optimize small to mid-size integers (even in exp. notation) */

/* Drop trailing zeros */

/* Align radix point to B1B digit boundary */

/* Upscale until desired number of bits are left of radix point */

/* Downscale until exactly number of bits are left of radix point */

/* FIXME: find a way to compute optimal sh */

/* Assemble desired bits into floating point variable */

/* Limit precision for denormal results */

/* Calculate bias term to force rounding, move out lower bits */

/* Process tail of decimal input so it can affect rounding */

/* Skip leading zeros */

/* Count zeros after the radix point before significand */


=== system/lib/libc/musl/src/internal/intscan.c ===
SHA256: ed96c758c94666f2557059bd8fca26db8340b9e6b417852f1599e7c30f67deca
Primary Git blob: a4a5ae861282863035a492ce8db0e18d4acfe3ac
/* Lookup table for digit values. -1==255>=36 -> invalid */


=== system/lib/libc/musl/src/internal/ksigaction.h ===
SHA256: e1b61f93586a56191b20ed80ad7430ed927c9a1185a8edece0e64119f06fc4d1
Primary Git blob: ef333f33ccfd3950b47eae7e11a365699a9dd488
/* This is the structure used for the rt_sigaction syscall on most archs,
 * but it can be overridden by a file with the same name in the top-level
 * arch dir for a given arch, if necessary. */


=== system/lib/libc/musl/src/internal/libm.h ===
SHA256: 8cb6cc4af4b96b92f5af9d4e20609c8b8456bded8908c3d58f5b8e8f37620f67
Primary Git blob: a47208aa6ad3c22d125d049237b547208d9ada79
/* This is the m68k variant of 80-bit long double, and this definition only works
 * on archs where the alignment requirement of uint64_t is <= 4. */

/* Support non-nearest rounding mode.  */

/* Support signaling NaNs.  */

/* Round x to nearest int in all rounding modes, ties have to be rounded
   consistently with converttoint so the results match.  If the result
   would be outside of [-2^31, 2^31-1] then the semantics is unspecified.  */

/* Convert x to nearest int in all rounding modes, ties have to be rounded
   consistently with roundtoint.  If the result is not representible in an
   int32_t then the semantics is unspecified.  */

/* Helps static branch prediction so hot path can be better optimized.  */

/* Evaluate an expression as the specified type. With standard excess
   precision handling a type cast or assignment is enough (with
   -ffloat-store an assignment is required, in old compilers argument
   passing and return statement may not drop excess precision).  */

/* fp_barrier returns its input, but limits code transformations
   as if it had a side-effect (e.g. observable io) and returned
   an arbitrary value.  */

/* fp_force_eval ensures that the input value is computed when that's
   otherwise unused.  To prevent the constant folding of the input
   expression, an additional fp_barrier may be needed or a compilation
   mode that does so (e.g. -frounding-math in gcc). Then it can be
   used to evaluate an expression for its fenv side-effects only.   */

/*
 * asm.js doesn't have user-accessible floating point exceptions, so there's
 * no point in trying to force expression evaluations to produce them.
 */

/* error handling functions */


=== system/lib/libc/musl/src/internal/locale_impl.h ===
SHA256: d7988edd03127df4cf479f922d9b5d6df5e507a874f95f399b268099747dd302
Primary Git blob: ed60d1600058990777d8e7be1ddff14ed058b552
// Disable message translation completely under emscripten since we don't

// support loading any actual locale data, and even looking up the current

// local via CURRENT_LOCALE via TLS is not free.


=== system/lib/libc/musl/src/internal/progname.c ===
SHA256: 51d5fe47275dc62b92ad16709c58734be9fd5fa432fb212c9ecfc0f1dd9e378b
Primary Git blob: ffefb792e69896996160cef28b04a7cc05cef27b
/*
 * Copyright 2022 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/musl/src/internal/proxying_notification_state.h ===
SHA256: 9d3999f4a3fa494676c203d078c01013860e49dcc8fc727013b2494e5c1ad6b9
Primary Git blob: 37a648315c00380464d12ab35b229372da87956a
/*
 * Copyright 2022 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// Flag values used when creating postMessage notifications and when freeing

// proxying queues. New postMessages are created for new work unless the

// relevant task queue is in state NOTIFICATION_PENDING and proxying queues can

// only be freed when all of their task queues are in NOTIFICATION_NONE state.


=== system/lib/libc/musl/src/internal/pthread_impl.h ===
SHA256: 9c0917012766522e7465195774c7ea766366e567a64f62df9535b1ae7d60b07d
Primary Git blob: 7f3a5483c802f37f95fab2791a7d7a0e04ef9952
/* Part 1 -- these fields may be external or
	 * internal (accessed via asm) ABI. Do not change. */

/* non-ABI */

/* Part 2 -- implementation details, non-ABI. */

/* Part 3 -- the positions of these fields relative to
	 * the end of the structure is external and internal ABI. */

// XXX Emscripten: Need some custom thread control structures.

// If --threadprofiler is enabled, this pointer is allocated to contain

// internal information about the thread state for profiling purposes.

// The TLS base to use the main module TLS data.  Secondary modules

// still require dynamic allocation.

// The lowest level of the proxying system. Other threads can enqueue

// messages on the mailbox and notify this thread to asynchronously

// process them once it returns to its event loop. When this thread is

// shut down, the mailbox is closed (see below) to prevent further

// messages from being enqueued and all the remaining queued messages

// are dequeued and their shutdown handlers are executed. This allows

// other threads waiting for their messages to be processed to be

// notified that their messages will not be processed after all.

// To ensure that no other thread is concurrently enqueueing a message

// when this thread shuts down, maintain an atomic refcount. Enqueueing

// threads atomically increment the count from a nonzero number to

// acquire the mailbox and decrement the count when they finish. When

// this thread shuts down it will atomically decrement the count and

// wait until it reaches 0, at which point the mailbox is considered

// closed and no further messages will be enqueued.

// Whether the thread has executed an `Atomics.waitAsync` on this

// pthread struct and can be notified of new mailbox messages via

// `Atomics.notify`. Otherwise, such as when the environment does not

// implement `Atomics.waitAsync` or when the thread has not had a chance

// to initialize itself yet, the notification has to fall back to the

// postMessage path. Once this becomes true, it remains true so we never

// fall back to postMessage unnecessarily.

// When dynamic linking is enabled, threads use this to facilitate the

// synchronization of loaded code between threads.

// See emscripten_futex_wait.c.

// XXX Emscripten: The spec allows detecting when multiple write locks would deadlock, so use an extra field

// _rw_wr_owner to record which thread owns the write lock in order to avoid hangs.

// Points to the pthread that currently has the write lock.

// Keep in sync with DEFAULT_PTHREAD_STACK_SIZE in settings.js


=== system/lib/libc/musl/src/internal/shgetc.c ===
SHA256: 0b076498bc7e64f0756692f431bf5d39ea3964a175b9eba4ce6cfe23d4c76dd2
Primary Git blob: 7455d2f00a04e477db9f4129fb4d5ba0809af1cb
/* The shcnt field stores the number of bytes read so far, offset by
 * the value of buf-rpos at the last function call (__shlim or __shgetc),
 * so that between calls the inline shcnt macro can add rpos-buf to get
 * the actual count. */

/* If lim is nonzero, rend must be a valid pointer. */


=== system/lib/libc/musl/src/internal/shgetc.h ===
SHA256: 8bf68f99a81d25c7a7b17b3f862498c94e5dbd6d2daa2a94765ef7a5d950563d
Primary Git blob: 9435381a61d1ee45c373c87bf7bcb5b43b370676
/* Scan helper "stdio" functions for use by scanf-family and strto*-family
 * functions. These accept either a valid stdio FILE, or a minimal pseudo
 * FILE whose buffer pointers point into a null-terminated string. In the
 * latter case, the sh_fromstring macro should be used to setup the FILE;
 * the rest of the structure can be left uninitialized.
 *
 * To begin using these functions, shlim must first be called on the FILE
 * to set a field width limit, or 0 for no limit. For string pseudo-FILEs,
 * a nonzero limit is not valid and produces undefined behavior. After that,
 * shgetc, shunget, and shcnt are valid as long as no other stdio functions
 * are called on the stream.
 *
 * When used with a real FILE object, shunget has only one byte of pushback
 * available. Further shunget (up to a limit of the stdio UNGET buffer size)
 * will adjust the position but will not restore the data to be read again.
 * This functionality is needed for the wcsto*-family functions, where it's
 * okay because the FILE will be discarded immediately anyway. When used
 * with string pseudo-FILEs, shunget has unlimited pushback, back to the
 * beginning of the string. */


=== system/lib/libc/musl/src/internal/stdio_impl.h ===
SHA256: 4165806d3887c63b442c7bf09d1e510df43130df700d47fc0804efa2d324d1d8
Primary Git blob: 18900fe1105844ee8832dc63c9f92996ce881f23
/* Caller-allocated FILE * operations */

// XXX EMSCRIPTEN


=== system/lib/libc/musl/src/internal/syscall.h ===
SHA256: 47d58145791b6e54ba70a15b904ae2f71c508bb012cd4c117a3a5afbdbe7c29f
Primary Git blob: 1a6c4313852d77e146ce85100c908b5a965bb2cf
// With emscripten we allow the passing of longer-than-word-sized

// argument (such as off_t on wasm32) and let binaryen handle splitting

// them into a pair of i32 arguments.

// __EMSCRIPTEN__

// __EMSCRIPTEN__

// __EMSCRIPTEN__

// __EMSCRIPTEN__

/* fixup legacy 16-bit junk */

/* fixup legacy 32-bit-vs-lfs64 junk */

/* Ensure that the plain syscall names are defined even for "time64-only"
 * archs. These facilitate callers passing null time arguments, and make
 * tests for establishing which to use/fallback-to more consistent when
 * they do need to be called with time arguments. */

/* SYS_semtimedop omitted because SYS_ipc may provide it */

/* socketcall calls */

/* This is valid only because all socket syscalls are made via
 * socketcall, which always fills unused argument slots with zeros. */

// __EMSCRIPTEN__


=== system/lib/libc/musl/src/ldso/dlerror.c ===
SHA256: c2b1bef1990e37c259b98d4eeddcc62f28c51026a5bcd62b7ebdc5b606935189
Primary Git blob: dae0f3a9b24a93d01882fdafd4ed91cb29416375
/* Atomic singly-linked list, used to store list of thread-local dlerror
 * buffers for deferred free. They cannot be freed at thread exit time
 * because, by the time it's known they can be freed, the exiting thread
 * is in a highly restrictive context where it cannot call (even the
 * libc-internal) free. It also can't take locks; thus the atomic list. */


=== system/lib/libc/musl/src/locale/catopen.c ===
SHA256: 7074bdbe709186a39d1c1e77e41574bf9b48fe98a463dc64333dbd4a12a8b453
Primary Git blob: 5bf2e9031dadf9bd31d71675fb9812a028d3dea4
/* Size recorded in the file must match file size; otherwise
	 * the information needed to unmap the file will be lost. */

/* Leading : or :: in NLSPATH is same as %N */


=== system/lib/libc/musl/src/locale/dcngettext.c ===
SHA256: d3c7cb390143fff1ba7df5bdda73fa749705761df4556ca2cb16010556a401d5
Primary Git blob: 56bee9931d14663766caccf5abc1cb3ca1430d68
/* match gnu gettext behaviour */

/* Logically split @mod suffix from locale name. */

/* Drop .charset identifier; it is not used. */

/* Try dropping @mod, _YY, then both. */

/* Non-plural-processing gettext forms pass a null pointer as
	 * msgid2 to request that dcngettext suppress plural processing. */


=== system/lib/libc/musl/src/locale/iconv.c ===
SHA256: d04b46b1e88f70e31681c21f7208464306dd4011457bb7ec114fb97f7c44aec2
Primary Git blob: 3dd9fd902e09d33e25a8826b363bfb1c778b208f
/* Definitions of charmaps. Each charmap consists of:
 * 1. Empty-string-terminated list of null-terminated aliases.
 * 2. Special type code or number of elided quads of entries.
 * 3. Character table (size determined by field 2), consisting
 *    of 5 bytes for every 4 characters, interpreted as 10-bit
 *    indices into the legacy_chars table. */

/* Table of characters that appear in legacy 8-bit codepages,
 * limited to 1024 slots (10 bit indices). The first 256 entries
 * are elided since those characters are obviously all included. */

/* "utf8" */

/* Adapt as needed */

/* A few HKSCS characters map to pairs of UCS
				 * characters. These are mapped to surrogate
				 * range in the hkscs table then hard-coded
				 * here. Ugly, yes. */

/* This failure condition should be unreachable, but
			 * is included to prevent decoder bugs from translating
			 * into advancement outside the output buffer range. */


=== system/lib/libc/musl/src/locale/langinfo.c ===
SHA256: e6ec8692b91ebb6dc49a00a36b51f6c9c26eaca82e6d21c937ad616a7db84946
Primary Git blob: 14773093b8b88a1daa138f816cb1aac2bfe5a29a
/* _NL_LOCALE_NAME extension */


=== system/lib/libc/musl/src/locale/locale_map.c ===
SHA256: 7a10efa548499c0d45c14542fbac473be4d348336e73f61bfd6aa8ca3834e95c
Primary Git blob: d696066cd3287d6d2d8cb277113688118d18bf41
/* Limit name length and forbid leading dot or any slashes. */

// don't support MUSL_LOCPATH which uses mmap

/* FIXME: add a default path? */

/* If no locale definition was found, make a locale map
	 * object anyway to store the name, which is kept for the
	 * sake of being able to do message translations at the
	 * application level. */

/* For LC_CTYPE, never return a null pointer unless the
	 * requested name was "C" or "POSIX". */


=== system/lib/libc/musl/src/locale/newlocale.c ===
SHA256: 55e7e5b9278283474650adbdb537562a9b269b9d29f1886de0f0431db3f2fc35
Primary Git blob: 9ac3cd386f99df95ba6e8f5a32a91b9c402db10d
/* For locales with allocated storage, modify in-place. */

/* Otherwise, first see if we can use one of the builtin locales.
	 * This makes the common usage case for newlocale, getting a C locale
	 * with predictable behavior, very fast, and more importantly, fail-safe. */

/* And provide builtins for the initial default locale, and a
	 * variant of the C locale honoring the default locale's encoding. */

/* If no builtin locale matched, attempt to allocate and copy. */


=== system/lib/libc/musl/src/locale/pleval.c ===
SHA256: 6cc5ed2cf8bf0c67e5ad7188e057f7115dc120f26a2fb6d41fe4211b550e2258
Primary Git blob: 04da1c45e85989c831d1e5deb84055498e0e42b9
/*
grammar:

Start = Expr ';'
Expr  = Or | Or '?' Expr ':' Expr
Or    = And | Or '||' And
And   = Eq | And '&&' Eq
Eq    = Rel | Eq '==' Rel | Eq '!=' Rel
Rel   = Add | Rel '<=' Add | Rel '>=' Add | Rel '<' Add | Rel '>' Add
Add   = Mul | Add '+' Mul | Add '-' Mul
Mul   = Prim | Mul '*' Prim | Mul '/' Prim | Mul '%' Prim
Prim  = '(' Expr ')' | '!' Prim | decimal | 'n'

internals:

recursive descent expression evaluator with stack depth limit.
for binary operators an operator-precedence parser is used.
eval* functions store the result of the parsed subexpression
and return a pointer to the next non-space character.
*/

/* note: >,< are accepted with or without = */

/*
		st->r (left hand side value) and st->op are now set,
		get the right hand side or back out if op has low prec,
		if op was missing then prec[op]==0
		*/


=== system/lib/libc/musl/src/locale/setlocale.c ===
SHA256: 70d643bc5628c281e59a0acaf47bc53fb8535488096c11fd31b5c59a296700e5
Primary Git blob: 360c4437644b88f86ac8b9f0db5d92915019c8d7
/* For LC_ALL, setlocale is required to return a string which
	 * encodes the current setting for all categories. The format of
	 * this string is unspecified, and only the following code, which
	 * performs both the serialization and deserialization, depends
	 * on the format, so it can easily be changed if needed. */


=== system/lib/libc/musl/src/locale/strxfrm.c ===
SHA256: 6ef828cfecd93527eec6cb476abfb69d7b8b7b149b157f9cb42d0d9a9db2db85
Primary Git blob: c66c62039d9593ac8b9d0ca732ce8c98e9107555
/* collate only by code points */


=== system/lib/libc/musl/src/locale/wcscoll.c ===
SHA256: 22e5a9b5e1f3623de61ea8282cf70738df2f180498c9aaa02dc3eadf8aaa5561
Primary Git blob: ad2cc691632a17caae724fed5602898dd92b9131
/* FIXME: stub */


=== system/lib/libc/musl/src/locale/wcsxfrm.c ===
SHA256: fc301b8c011b09d9fe6a51260a7fe395d4242477c0b8264a5f3650c609e29dc0
Primary Git blob: 05e3e1158188e51013b986513e517dfd14866106
/* collate only by code points */


=== system/lib/libc/musl/src/malloc/reallocarray.c ===
SHA256: b998788cbc4fe6c84c050d8a0498fae863d2ec599dddfbbff4ac5bd895db4de7
Primary Git blob: bcf5f4346d0fb273ec27513b9b6327a2168d1a29
/* Must be weak so that lsan can override */


=== system/lib/libc/musl/src/math/__cos.c ===
SHA256: 3f0f774aab60a18d7ef935ffdf121bcda17cbadabff14096c614da22e31a42c1
Primary Git blob: 46cefb38134398a4e0e7b40621eb6ea6e514ca38
/* origin: FreeBSD /usr/src/lib/msun/src/k_cos.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * __cos( x,  y )
 * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
 * Input x is assumed to be bounded by ~pi/4 in magnitude.
 * Input y is the tail of x.
 *
 * Algorithm
 *      1. Since cos(-x) = cos(x), we need only to consider positive x.
 *      2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
 *      3. cos(x) is approximated by a polynomial of degree 14 on
 *         [0,pi/4]
 *                                       4            14
 *              cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
 *         where the remez error is
 *
 *      |              2     4     6     8     10    12     14 |     -58
 *      |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x  +C6*x  )| <= 2
 *      |                                                      |
 *
 *                     4     6     8     10    12     14
 *      4. let r = C1*x +C2*x +C3*x +C4*x +C5*x  +C6*x  , then
 *             cos(x) ~ 1 - x*x/2 + r
 *         since cos(x+y) ~ cos(x) - sin(x)*y
 *                        ~ cos(x) - x*y,
 *         a correction term is necessary in cos(x) and hence
 *              cos(x+y) = 1 - (x*x/2 - (r - x*y))
 *         For better accuracy, rearrange to
 *              cos(x+y) ~ w + (tmp + (r-x*y))
 *         where w = 1 - x*x/2 and tmp is a tiny correction term
 *         (1 - x*x/2 == w + tmp exactly in infinite precision).
 *         The exactness of w + tmp in infinite precision depends on w
 *         and tmp having the same precision as x.  If they have extra
 *         precision due to compiler bugs, then the extra precision is
 *         only good provided it is retained in all terms of the final
 *         expression for cos().  Retention happens in all cases tested
 *         under FreeBSD, so don't pessimize things by forcibly clipping
 *         any extra precision in w.
 */

/* 0x3FA55555, 0x5555554C */

/* 0xBF56C16C, 0x16C15177 */

/* 0x3EFA01A0, 0x19CB1590 */

/* 0xBE927E4F, 0x809C52AD */

/* 0x3E21EE9E, 0xBDB4B1C4 */

/* 0xBDA8FAE9, 0xBE8838D4 */


=== system/lib/libc/musl/src/math/__cosdf.c ===
SHA256: 0ba872cc7e26b93bb9784d19fee84b263e1fa3543a76ec3c0893aea47453a2a7
Primary Git blob: 2124989b3299e53893f2fc9267567e2e7738509b
/* origin: FreeBSD /usr/src/lib/msun/src/k_cosf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Debugged and optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */

/* -0.499999997251031003120 */

/*  0.0416666233237390631894 */

/* -0.00138867637746099294692 */

/*  0.0000243904487962774090654 */

/* Try to optimize for parallel evaluation as in __tandf.c. */


=== system/lib/libc/musl/src/math/__cosl.c ===
SHA256: fd644ce4ab8797b1220e2197b284212094a3b299bdf2c4faf66ead81b0fc620d
Primary Git blob: fa522ddd7ae263b02a0dfb00b04486aa4ca90af5
/* origin: FreeBSD /usr/src/lib/msun/ld80/k_cosl.c */

/* origin: FreeBSD /usr/src/lib/msun/ld128/k_cosl.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * ld80 version of __cos.c.  See __cos.c for most comments.
 */

/*
 * Domain [-0.7854, 0.7854], range ~[-2.43e-23, 2.425e-23]:
 * |cos(x) - c(x)| < 2**-75.1
 *
 * The coefficients of c(x) were generated by a pari-gp script using
 * a Remez algorithm that searches for the best higher coefficients
 * after rounding leading coefficients to a specified precision.
 *
 * Simpler methods like Chebyshev or basic Remez barely suffice for
 * cos() in 64-bit precision, because we want the coefficient of x^2
 * to be precisely -0.5 so that multiplying by it is exact, and plain
 * rounding of the coefficients of a good polynomial approximation only
 * gives this up to about 64-bit precision.  Plain rounding also gives
 * a mediocre approximation for the coefficient of x^4, but a rounding
 * error of 0.5 ulps for this coefficient would only contribute ~0.01
 * ulps to the final error, so this is unimportant.  Rounding errors in
 * higher coefficients are even less important.
 *
 * In fact, coefficients above the x^4 one only need to have 53-bit
 * precision, and this is more efficient.  We get this optimization
 * almost for free from the complications needed to search for the best
 * higher coefficients.
 */

/*  0xaaaaaaaaaaaaaa9b.0p-68 */

/* -0x16c16c16c16c10.0p-62 */

/*  0x1a01a01a018e22.0p-68 */

/* -0x127e4fb7602f22.0p-74 */

/*  0x11eed8caaeccf1.0p-81 */

/* -0x19393412bd1529.0p-89 */

/*  0x1aac9d9af5c43e.0p-97 */

/*
 * ld128 version of __cos.c.  See __cos.c for most comments.
 */

/*
 * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]:
 * |cos(x) - c(x))| < 2**-122.0
 *
 * 113-bit precision requires more care than 64-bit precision, since
 * simple methods give a minimax polynomial with coefficient for x^2
 * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
 * above for more details.
 */


=== system/lib/libc/musl/src/math/__expo2.c ===
SHA256: 29cc9dd6d656cd0fbf921a8a1aeee81b430558d880194832a8d44d82c8d37d94
Primary Git blob: 248f052b98b65ec64ba19943781b03e7ace02712
/* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */

/* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */

/* note that k is odd and scale*scale overflows */

/* exp(x - k ln2) * 2**(k-1) */

/* in directed rounding correct sign before rounding or overflow is important */


=== system/lib/libc/musl/src/math/__expo2f.c ===
SHA256: 329525397cc2169cad5ab60d2f75886a2ea97f9b27dbe708e9773ea77f20fa4f
Primary Git blob: 538eb09c0724c2583398054560a6261a6f770441
/* k is such that k*ln2 has minimal relative error and x - kln2 > log(FLT_MIN) */

/* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */

/* note that k is odd and scale*scale overflows */

/* exp(x - k ln2) * 2**(k-1) */

/* in directed rounding correct sign before rounding or overflow is important */


=== system/lib/libc/musl/src/math/__fpclassifyl.c ===
SHA256: 79a2f6d1f56dd3c3cc316d6fc5891ec0bd04b69a1b0f6688e028fb29c8f85a84
Primary Git blob: e41781b689af7f7db420fc437cc4a72e4dd00c33
/* The x86 variant of 80-bit extended precision only admits
		 * one representation of each infinity, with the mantissa msb
		 * necessarily set. The version with it clear is invalid/nan.
		 * The m68k variant, however, allows either, and tooling uses
		 * the version with it clear. */


=== system/lib/libc/musl/src/math/__invtrigl.c ===
SHA256: 1763b953d04928db3952438204678e5b9036a4a273bafe6f3cc06a0694e51f91
Primary Git blob: 48f83aaf8c7f8215766e2c902a38e6fbf32c8b9f
/* used in asinl() and acosl() */

/* R(x^2) is a rational approximation of (asin(x)-x)/x^3 with Remez algorithm */


=== system/lib/libc/musl/src/math/__invtrigl.h ===
SHA256: c48442943bf12b09d6961724495b9aed5761556b86df2c449af493c17bca257f
Primary Git blob: bee7931720d8e9f81f0ffd148a81e61966e8e79c
/* shared by acosl, asinl and atan2l */


=== system/lib/libc/musl/src/math/__polevll.c ===
SHA256: 4fef0127318ba19fd5796b6b69a938030d22adb16aaab2ade3e634c8c5c93479
Primary Git blob: ce1a84046b83679b95dbf54b84a6afc03a83df69
/* origin: OpenBSD /usr/src/lib/libm/src/polevll.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Evaluate polynomial
 *
 *
 * SYNOPSIS:
 *
 * int N;
 * long double x, y, coef[N+1], polevl[];
 *
 * y = polevll( x, coef, N );
 *
 *
 * DESCRIPTION:
 *
 * Evaluates polynomial of degree N:
 *
 *                     2          N
 * y  =  C  + C x + C x  +...+ C x
 *        0    1     2          N
 *
 * Coefficients are stored in reverse order:
 *
 * coef[0] = C  , ..., coef[N] = C  .
 *            N                   0
 *
 *  The function p1evll() assumes that coef[N] = 1.0 and is
 * omitted from the array.  Its calling arguments are
 * otherwise the same as polevll().
 *
 *
 * SPEED:
 *
 * In the interest of speed, there are no checks for out
 * of bounds arithmetic.  This routine is used by most of
 * the functions in the library.  Depending on available
 * equipment features, the user may wish to rewrite the
 * program in microcode or assembly language.
 *
 */

/*
 * Polynomial evaluator:
 *  P[0] x^n  +  P[1] x^(n-1)  +  ...  +  P[n]
 */

/*
 * Polynomial evaluator:
 *  x^n  +  P[0] x^(n-1)  +  P[1] x^(n-2)  +  ...  +  P[n]
 */


=== system/lib/libc/musl/src/math/__rem_pio2.c ===
SHA256: 938329e0939cd83ee2185a52154b41242f618d4a6df1b08395f344da33d4f1e6
Primary Git blob: dcf672fbd70344d40b308cf0c0a11b862bea6dca
/* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 * Optimized by Bruce D. Evans.
 */

/* __rem_pio2(x,y)
 *
 * return the remainder of x rem pi/2 in y[0]+y[1]
 * use __rem_pio2_large() for large x
 */

/*
 * invpio2:  53 bits of 2/pi
 * pio2_1:   first  33 bit of pi/2
 * pio2_1t:  pi/2 - pio2_1
 * pio2_2:   second 33 bit of pi/2
 * pio2_2t:  pi/2 - (pio2_1+pio2_2)
 * pio2_3:   third  33 bit of pi/2
 * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
 */

/* 0x3FE45F30, 0x6DC9C883 */

/* 0x3FF921FB, 0x54400000 */

/* 0x3DD0B461, 0x1A626331 */

/* 0x3DD0B461, 0x1A600000 */

/* 0x3BA3198A, 0x2E037073 */

/* 0x3BA3198A, 0x2E000000 */

/* 0x397B839A, 0x252049C1 */

/* caller must handle the case when reduction is not needed: |x| ~<= pi/4 */

/* |x| ~<= 5pi/4 */

/* |x| ~= pi/2 or 2pi/2 */

/* cancellation -- use medium case */

/* |x| ~<= 3pi/4 */

/* one round good to 85 bits */

/* |x| ~<= 9pi/4 */

/* |x| ~<= 7pi/4 */

/* |x| ~= 3pi/2 */

/* |x| ~= 4pi/2 */

/* |x| ~< 2^20*(pi/2), medium size */

/* rint(x/(pi/2)) */

/* 1st round, good to 85 bits */

/* Matters with directed rounding. */

/* 2nd round, good to 118 bits */

/* 3rd round, good to 151 bits, covers all cases */

/*
	 * all other (large) arguments
	 */

/* x is inf or NaN */

/* set z = scalbn(|x|,-ilogb(x)+23) */

/* skip zero terms, first term is non-zero */


=== system/lib/libc/musl/src/math/__rem_pio2_large.c ===
SHA256: b97f19fb5951c83a0c10506fab35646caefde13bd03100ad2af55ef00af0b9fb
Primary Git blob: 958f28c2557caf23ce9476771f1787cf071d19de
/* origin: FreeBSD /usr/src/lib/msun/src/k_rem_pio2.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * __rem_pio2_large(x,y,e0,nx,prec)
 * double x[],y[]; int e0,nx,prec;
 *
 * __rem_pio2_large return the last three digits of N with
 *              y = x - N*pi/2
 * so that |y| < pi/2.
 *
 * The method is to compute the integer (mod 8) and fraction parts of
 * (2/pi)*x without doing the full multiplication. In general we
 * skip the part of the product that are known to be a huge integer (
 * more accurately, = 0 mod 8 ). Thus the number of operations are
 * independent of the exponent of the input.
 *
 * (2/pi) is represented by an array of 24-bit integers in ipio2[].
 *
 * Input parameters:
 *      x[]     The input value (must be positive) is broken into nx
 *              pieces of 24-bit integers in double precision format.
 *              x[i] will be the i-th 24 bit of x. The scaled exponent
 *              of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
 *              match x's up to 24 bits.
 *
 *              Example of breaking a double positive z into x[0]+x[1]+x[2]:
 *                      e0 = ilogb(z)-23
 *                      z  = scalbn(z,-e0)
 *              for i = 0,1,2
 *                      x[i] = floor(z)
 *                      z    = (z-x[i])*2**24
 *
 *
 *      y[]     ouput result in an array of double precision numbers.
 *              The dimension of y[] is:
 *                      24-bit  precision       1
 *                      53-bit  precision       2
 *                      64-bit  precision       2
 *                      113-bit precision       3
 *              The actual value is the sum of them. Thus for 113-bit
 *              precison, one may have to do something like:
 *
 *              long double t,w,r_head, r_tail;
 *              t = (long double)y[2] + (long double)y[1];
 *              w = (long double)y[0];
 *              r_head = t+w;
 *              r_tail = w - (r_head - t);
 *
 *      e0      The exponent of x[0]. Must be <= 16360 or you need to
 *              expand the ipio2 table.
 *
 *      nx      dimension of x[]
 *
 *      prec    an integer indicating the precision:
 *                      0       24  bits (single)
 *                      1       53  bits (double)
 *                      2       64  bits (extended)
 *                      3       113 bits (quad)
 *
 * External function:
 *      double scalbn(), floor();
 *
 *
 * Here is the description of some local variables:
 *
 *      jk      jk+1 is the initial number of terms of ipio2[] needed
 *              in the computation. The minimum and recommended value
 *              for jk is 3,4,4,6 for single, double, extended, and quad.
 *              jk+1 must be 2 larger than you might expect so that our
 *              recomputation test works. (Up to 24 bits in the integer
 *              part (the 24 bits of it that we compute) and 23 bits in
 *              the fraction part may be lost to cancelation before we
 *              recompute.)
 *
 *      jz      local integer variable indicating the number of
 *              terms of ipio2[] used.
 *
 *      jx      nx - 1
 *
 *      jv      index for pointing to the suitable ipio2[] for the
 *              computation. In general, we want
 *                      ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
 *              is an integer. Thus
 *                      e0-3-24*jv >= 0 or (e0-3)/24 >= jv
 *              Hence jv = max(0,(e0-3)/24).
 *
 *      jp      jp+1 is the number of terms in PIo2[] needed, jp = jk.
 *
 *      q[]     double array with integral value, representing the
 *              24-bits chunk of the product of x and 2/pi.
 *
 *      q0      the corresponding exponent of q[0]. Note that the
 *              exponent for q[i] would be q0-24*i.
 *
 *      PIo2[]  double precision array, obtained by cutting pi/2
 *              into 24 bits chunks.
 *
 *      f[]     ipio2[] in floating point
 *
 *      iq[]    integer array by breaking up q[] in 24-bits chunk.
 *
 *      fq[]    final product of x*(2/pi) in fq[0],..,fq[jk]
 *
 *      ih      integer. If >0 it indicates q[] is >= 0.5, hence
 *              it also indicates the *sign* of the result.
 *
 */

/*
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

/* initial value for jk */

/*
 * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
 *
 *              integer array, contains the (24*i)-th to (24*i+23)-th
 *              bit of 2/pi after binary point. The corresponding
 *              floating value is
 *
 *                      ipio2[i] * 2^(-24(i+1)).
 *
 * NB: This table must have at least (e0-3)/24 + jk terms.
 *     For quad precision (e0 <= 16360, jk = 6), this is 686.
 */

/* 0x3FF921FB, 0x40000000 */

/* 0x3E74442D, 0x00000000 */

/* 0x3CF84698, 0x80000000 */

/* 0x3B78CC51, 0x60000000 */

/* 0x39F01B83, 0x80000000 */

/* 0x387A2520, 0x40000000 */

/* 0x36E38222, 0x80000000 */

/* 0x3569F31D, 0x00000000 */

/* initialize jk*/

/* determine jx,jv,q0, note that 3>q0 */

/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */

/* compute q[0],q[1],...q[jk] */

/* distill q[] into iq[] reversingly */

/* compute n */

/* actual value of z */

/* trim off integer >= 8 */

/* need iq[jz-1] to determine n */

/* q > 0.5 */

/* compute 1-q */

/* rare case: chance is 1 in 12 */

/* check if recomputation is needed */

/* need recomputation */

/* k = no. of terms needed */

/* add q[jz+1] to q[jz+k] */

/* chop off zero terms */

/* break z into 24-bit if necessary */

/* convert integer "bit" chunk to floating-point value */

/* compute PIo2[0,...,jp]*q[jz,...,0] */

/* compress fq[] into y[] */

// TODO: drop excess precision here once double_t is used

/* painful */


=== system/lib/libc/musl/src/math/__rem_pio2f.c ===
SHA256: b73a0219ba4a34e39ed904b5008126ff1b12dfa1a4a380941363c8db5088d756
Primary Git blob: e67656431a825480c779fd08ab0735f1a6a63572
/* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2f.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Debugged and optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* __rem_pio2f(x,y)
 *
 * return the remainder of x rem pi/2 in *y
 * use double precision for everything except passing x
 * use __rem_pio2_large() for large x
 */

/*
 * invpio2:  53 bits of 2/pi
 * pio2_1:   first 25 bits of pi/2
 * pio2_1t:  pi/2 - pio2_1
 */

/* 0x3FE45F30, 0x6DC9C883 */

/* 0x3FF921FB, 0x50000000 */

/* 0x3E5110b4, 0x611A6263 */

/* 25+53 bit pi is good enough for medium size */

/* |x| ~< 2^28*(pi/2), medium size */

/* Use a specialized rint() to get fn. */

/* Matters with directed rounding. */

/* x is inf or NaN */

/* scale x into [2^23, 2^24-1] */

/* e0 = ilogb(|x|)-23, positive */


=== system/lib/libc/musl/src/math/__rem_pio2l.c ===
SHA256: 70f1c69285c0d211d696d5c048e269d46000e5d75fc6a80623ef45e861447a94
Primary Git blob: 236b2def3d276e52152794d7fc91e2a1820a0b08
/* origin: FreeBSD /usr/src/lib/msun/ld80/e_rem_pio2.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 * Optimized by Bruce D. Evans.
 */

/* ld80 and ld128 version of __rem_pio2(x,y)
 *
 * return the remainder of x rem pi/2 in y[0]+y[1]
 * use __rem_pio2_large() for large x
 */

/* u ~< 0x1p25*pi/2 */

/*
 * invpio2:  64 bits of 2/pi
 * pio2_1:   first  39 bits of pi/2
 * pio2_1t:  pi/2 - pio2_1
 * pio2_2:   second 39 bits of pi/2
 * pio2_2t:  pi/2 - (pio2_1+pio2_2)
 * pio2_3:   third  39 bits of pi/2
 * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
 */

/* 0x3FF921FB, 0x54444000 */

/* -0x12e7b967674000.0p-92 */

/*  0x18a2e037074000.0p-133 */

/*  0xa2f9836e4e44152a.0p-64 */

/* -0x973dcb3b399d747f.0p-103 */

/*  0xc51701b839a25205.0p-144 */

/* -0xbb5bf6c7ddd660ce.0p-185 */

/* u ~< 0x1p45*pi/2 */

/*  0x145f306dc9c882a53f84eafa3ea6a.0p-113 */

/*  0x1921fb54442d18469800000000000.0p-112 */

/*  0x13198a2e03707344a4093822299f3.0p-181 */

/*  0x13198a2e03707344a400000000000.0p-181 */

/*  0x127044533e63a0105df531d89cd91.0p-254 */

/*  0x127044533e63a0105e00000000000.0p-254 */

/* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */

/* rint(x/(pi/2)) */

/* 1st round good to 102/180 bits (ld80/ld128) */

/* Matters with directed rounding. */

/* 2nd iteration needed, good to 141/248 (ld80/ld128) */

/* 3rd iteration, good to 180/316 bits */

/* will cover all possible cases (not verified for ld128) */

/*
	 * all other (large) arguments
	 */

/* x is inf or NaN */

/* set z = scalbn(|x|,-ilogb(x)+23) */

/* TODO: for ld128 this does not follow the recommendation of the
	comments of __rem_pio2_large which seem wrong if |ty[0]| > |ty[1]+ty[2]| */


=== system/lib/libc/musl/src/math/__signbit.c ===
SHA256: 4a0fb47ca9b52e417050707156bd9f70eb62f5669aa4629b8d96ab03f5790d22
Primary Git blob: e700b6b75fcb91e1919ad64b7da4e8c6a16f6065
// FIXME: macro in math.h


=== system/lib/libc/musl/src/math/__signbitf.c ===
SHA256: 98bc074237938654f4bce1f5bd5bf94f98f808399f5221595b022850bd7d6010
Primary Git blob: 40ad3cfd0cbe6e4d420df2c8b3f9355bf4152cd5
// FIXME: macro in math.h


=== system/lib/libc/musl/src/math/__sin.c ===
SHA256: f3a37ef9bcfb8a2f9c809d8c7f1aa2c17c8c3319ad7fb2fe7c0a6284ea8859d2
Primary Git blob: 40309496646ea67bc247a46b8cd363a73ca9801e
/* origin: FreeBSD /usr/src/lib/msun/src/k_sin.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* __sin( x, y, iy)
 * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
 * Input x is assumed to be bounded by ~pi/4 in magnitude.
 * Input y is the tail of x.
 * Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
 *
 * Algorithm
 *      1. Since sin(-x) = -sin(x), we need only to consider positive x.
 *      2. Callers must return sin(-0) = -0 without calling here since our
 *         odd polynomial is not evaluated in a way that preserves -0.
 *         Callers may do the optimization sin(x) ~ x for tiny x.
 *      3. sin(x) is approximated by a polynomial of degree 13 on
 *         [0,pi/4]
 *                               3            13
 *              sin(x) ~ x + S1*x + ... + S6*x
 *         where
 *
 *      |sin(x)         2     4     6     8     10     12  |     -58
 *      |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x  +S6*x   )| <= 2
 *      |  x                                               |
 *
 *      4. sin(x+y) = sin(x) + sin'(x')*y
 *                  ~ sin(x) + (1-x*x/2)*y
 *         For better accuracy, let
 *                   3      2      2      2      2
 *              r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
 *         then                   3    2
 *              sin(x) = x + (S1*x + (x *(r-y/2)+y))
 */

/* 0xBFC55555, 0x55555549 */

/* 0x3F811111, 0x1110F8A6 */

/* 0xBF2A01A0, 0x19C161D5 */

/* 0x3EC71DE3, 0x57B1FE7D */

/* 0xBE5AE5E6, 0x8A2B9CEB */

/* 0x3DE5D93A, 0x5ACFD57C */


=== system/lib/libc/musl/src/math/__sindf.c ===
SHA256: de7026bcd159b7d06a8cbcc162df722014f3b1a3cc4183116b6b7829eef1d118
Primary Git blob: 8fec2a3f660c627b9dd575f96601c9530dc9a67e
/* origin: FreeBSD /usr/src/lib/msun/src/k_sinf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). */

/* -0.166666666416265235595 */

/*  0.0083333293858894631756 */

/* -0.000198393348360966317347 */

/*  0.0000027183114939898219064 */

/* Try to optimize for parallel evaluation as in __tandf.c. */


=== system/lib/libc/musl/src/math/__sinl.c ===
SHA256: b6dfffc327cac147a0a2b17a12e9f4ec8ff6df463733db55c316a55ef4bcdb96
Primary Git blob: 2525bbe86689080b4457ba7d5b1ea53793b90d9c
/* origin: FreeBSD /usr/src/lib/msun/ld80/k_sinl.c */

/* origin: FreeBSD /usr/src/lib/msun/ld128/k_sinl.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * ld80 version of __sin.c.  See __sin.c for most comments.
 */

/*
 * Domain [-0.7854, 0.7854], range ~[-1.89e-22, 1.915e-22]
 * |sin(x)/x - s(x)| < 2**-72.1
 *
 * See __cosl.c for more details about the polynomial.
 */

/* -0xaaaaaaaaaaaaaaab.0p-66 */

/*  0x11111111111111.0p-59 */

/* -0x1a01a01a019f81.0p-65 */

/*  0x171de3a55560f7.0p-71 */

/* -0x1ae64564f16cad.0p-78 */

/*  0x161242b90243b5.0p-85 */

/* -0x1ae42ebd1b2e00.0p-93 */

/*  0x179372ea0b3f64.0p-101 */

/*
 * ld128 version of __sin.c.  See __sin.c for most comments.
 */

/*
 * Domain [-0.7854, 0.7854], range ~[-1.53e-37, 1.659e-37]
 * |sin(x)/x - s(x)| < 2**-122.1
 *
 * See __cosl.c for more details about the polynomial.
 */


=== system/lib/libc/musl/src/math/__tan.c ===
SHA256: e18b65b69fced8dbb2d3ed1a3dc6daea0e9f857f2762f274380bd89a6f89d2c4
Primary Git blob: 8019844d3bc2dac0916290ecb5c05a63e8b7ffc8
/* origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */

/*
 * ====================================================
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* __tan( x, y, k )
 * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854
 * Input x is assumed to be bounded by ~pi/4 in magnitude.
 * Input y is the tail of x.
 * Input odd indicates whether tan (if odd = 0) or -1/tan (if odd = 1) is returned.
 *
 * Algorithm
 *      1. Since tan(-x) = -tan(x), we need only to consider positive x.
 *      2. Callers must return tan(-0) = -0 without calling here since our
 *         odd polynomial is not evaluated in a way that preserves -0.
 *         Callers may do the optimization tan(x) ~ x for tiny x.
 *      3. tan(x) is approximated by a odd polynomial of degree 27 on
 *         [0,0.67434]
 *                               3             27
 *              tan(x) ~ x + T1*x + ... + T13*x
 *         where
 *
 *              |tan(x)         2     4            26   |     -59.2
 *              |----- - (1+T1*x +T2*x +.... +T13*x    )| <= 2
 *              |  x                                    |
 *
 *         Note: tan(x+y) = tan(x) + tan'(x)*y
 *                        ~ tan(x) + (1+x*x)*y
 *         Therefore, for better accuracy in computing tan(x+y), let
 *                   3      2      2       2       2
 *              r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
 *         then
 *                                  3    2
 *              tan(x+y) = x + (T1*x + (x *(r+y)+y))
 *
 *      4. For x in [0.67434,pi/4],  let y = pi/4 - x, then
 *              tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
 *                     = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
 */

/* 3FD55555, 55555563 */

/* 3FC11111, 1110FE7A */

/* 3FABA1BA, 1BB341FE */

/* 3F9664F4, 8406D637 */

/* 3F8226E3, E96E8493 */

/* 3F6D6D22, C9560328 */

/* 3F57DBC8, FEE08315 */

/* 3F4344D8, F2F26501 */

/* 3F3026F7, 1A8D1068 */

/* 3F147E88, A03792A6 */

/* 3F12B80F, 32F0A7E9 */

/* BEF375CB, DB605373 */

/* 3EFB2A70, 74BF7AD4 */

/* 3FE921FB, 54442D18 */

/* 3C81A626, 33145C07 */

/* |x| >= 0.6744 */

/*
	 * Break x^5*(T[1]+x^2*T[2]+...) into
	 * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
	 * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
	 */

/* -1.0/(x+r) has up to 2ulp error, so compute it accurately */

/* w0+v = r+x */


=== system/lib/libc/musl/src/math/__tandf.c ===
SHA256: 60455f3cc0ac743f3eaf0017a3a4f0adbab37c0ee30d29397852d22904c40444
Primary Git blob: 25047eeee9c098894010a3984372ba63cb698656
/* origin: FreeBSD /usr/src/lib/msun/src/k_tanf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */

/* 0.333331395030791399758 */

/* 0.133392002712976742718 */

/* 0.0533812378445670393523 */

/* 0.0245283181166547278873 */

/* 0.00297435743359967304927 */

/* 0.00946564784943673166728 */

/*
	 * Split up the polynomial into small independent terms to give
	 * opportunities for parallel evaluation.  The chosen splitting is
	 * micro-optimized for Athlons (XP, X64).  It costs 2 multiplications
	 * relative to Horner's method on sequential machines.
	 *
	 * We add the small terms from lowest degree up for efficiency on
	 * non-sequential machines (the lowest degree terms tend to be ready
	 * earlier).  Apart from this, we don't care about order of
	 * operations, and don't need to to care since we have precision to
	 * spare.  However, the chosen splitting is good for accuracy too,
	 * and would give results as accurate as Horner's method if the
	 * small terms were added from highest degree down.
	 */


=== system/lib/libc/musl/src/math/__tanl.c ===
SHA256: 3788db7251d2e14b17e761bc2eccd0d8faa3c72c16eef7a56ca2ca75eca177df
Primary Git blob: 54abc3daf1ad126306b363151aaa8dcca5928423
/* origin: FreeBSD /usr/src/lib/msun/ld80/k_tanl.c */

/* origin: FreeBSD /usr/src/lib/msun/ld128/k_tanl.c */

/*
 * ====================================================
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
 * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
 *
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * ld80 version of __tan.c.  See __tan.c for most comments.
 */

/*
 * Domain [-0.67434, 0.67434], range ~[-2.25e-22, 1.921e-22]
 * |tan(x)/x - t(x)| < 2**-71.9
 *
 * See __cosl.c for more details about the polynomial.
 */

/*  0xaaaaaaaaaaaaaaa5.0p-65 */

/*  0x88888888888893c3.0p-66 */

/*  0xdd0dd0dd0dc13ba2.0p-68 */

/*  0xc90fdaa22168c235.0p-64 */

/* -0xece675d1fc8f8cbb.0p-130 */

/*  0x1664f4882cc1c2.0p-58 */

/*  0x1226e355c17612.0p-59 */

/*  0x1d6d3d185d7ff8.0p-61 */

/*  0x17da354aa3f96b.0p-62 */

/*  0x13559358685b83.0p-63 */

/*  0x1f56242026b5be.0p-65 */

/*  0x1977efc26806f4.0p-66 */

/*  0x14275a09b3ceac.0p-67 */

/*  0x12f5e563e5487e.0p-68 */

/*  0x144c0d80cc6896.0p-71 */

/*  0x106b59141a6cb3.0p-69 */

/* -0x1b5abef3ba4b59.0p-71 */

/*  0x13835436c0c87f.0p-71 */

/*
 * ld128 version of __tan.c.  See __tan.c for most comments.
 */

/*
 * Domain [-0.67434, 0.67434], range ~[-3.37e-36, 1.982e-37]
 * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37)
 *
 * See __cosl.c for more details about the polynomial.
 */

/*  0x1e8a7592977938.0p-78 */

/*  0x19baa1b1223219.0p-79 */

/*  0x107385dfb24529.0p-80 */

/*  0x1dc6c702a05262.0p-81 */

/* -0x19ecef3569ebb6.0p-82 */

/*  0x194c0668da786a.0p-81 */

/* -0x12e763b8845268.0p-81 */

/*  0x1a92fc98c29554.0p-82 */

/* -0x151106cbc779a9.0p-83 */

/*  0x147edbdba6f43a.0p-85 */

/*
	 * if allow error up to 2 ulp, simply return
	 * -1.0 / (x+r) here
	 */

/* compute -1.0 / (x+r) accurately */

/* z+v = r+x */

/* a = -1.0/w */


=== system/lib/libc/musl/src/math/acos.c ===
SHA256: cc6f9017e7e2e0ef01516fa12c68aa63865e6415c90dc039dfce9abffae09a4c
Primary Git blob: ea9c87bf087809f9a6b1fa6a2ed2f065d8184f72
/* origin: FreeBSD /usr/src/lib/msun/src/e_acos.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* acos(x)
 * Method :
 *      acos(x)  = pi/2 - asin(x)
 *      acos(-x) = pi/2 + asin(x)
 * For |x|<=0.5
 *      acos(x) = pi/2 - (x + x*x^2*R(x^2))     (see asin.c)
 * For x>0.5
 *      acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
 *              = 2asin(sqrt((1-x)/2))
 *              = 2s + 2s*z*R(z)        ...z=(1-x)/2, s=sqrt(z)
 *              = 2f + (2c + 2s*z*R(z))
 *     where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
 *     for f so that f+c ~ sqrt(z).
 * For x<-0.5
 *      acos(x) = pi - 2asin(sqrt((1-|x|)/2))
 *              = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
 *
 * Special cases:
 *      if x is NaN, return x itself;
 *      if |x|>1, return NaN with invalid signal.
 *
 * Function needed: sqrt
 */

/* 0x3FF921FB, 0x54442D18 */

/* 0x3C91A626, 0x33145C07 */

/* 0x3FC55555, 0x55555555 */

/* 0xBFD4D612, 0x03EB6F7D */

/* 0x3FC9C155, 0x0E884455 */

/* 0xBFA48228, 0xB5688F3B */

/* 0x3F49EFE0, 0x7501B288 */

/* 0x3F023DE1, 0x0DFDF709 */

/* 0xC0033A27, 0x1C8A2D4B */

/* 0x40002AE5, 0x9C598AC8 */

/* 0xBFE6066C, 0x1B8D0159 */

/* 0x3FB3B8C5, 0xB12E9282 */

/* |x| >= 1 or nan */

/* acos(1)=0, acos(-1)=pi */

/* |x| < 0.5 */

/* |x| < 2**-57 */

/* x < -0.5 */

/* x > 0.5 */


=== system/lib/libc/musl/src/math/acosf.c ===
SHA256: b20b3dcb58ce7cc55963945f8cb83efbf064b29d2da3011f2cec5d08459f2aa7
Primary Git blob: 8ee1a71d0cc2965e08e170be1dc4529d0165f3b4
/* origin: FreeBSD /usr/src/lib/msun/src/e_acosf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x3fc90fda */

/* 0x33a22168 */

/* |x| >= 1 or nan */

/* |x| < 0.5 */

/* |x| < 2**-26 */

/* x < -0.5 */

/* x > 0.5 */


=== system/lib/libc/musl/src/math/acosh.c ===
SHA256: eef97dad984a78f7afabb0a62aee7b11113753984157cf44ffb8ac137697207c
Primary Git blob: badbf9081e644ff9df80bd2ae86cfc32e32a888b
/* acosh(x) = log(x + sqrt(x*x-1)) */

/* x < 1 domain error is handled in the called functions */

/* |x| < 2, up to 2ulp error in [1,1.125] */

/* |x| < 0x1p26 */

/* |x| >= 0x1p26 or nan */


=== system/lib/libc/musl/src/math/acoshf.c ===
SHA256: 063f1480944d44cc850f2c75215aff6d30c8ba5b34e9a883c7e62d206a64bcdf
Primary Git blob: b773d48e2b84627e0d405a30d9ca8c2994aafe1c
/* acosh(x) = log(x + sqrt(x*x-1)) */

/* |x| < 2, invalid if x < 1 */

/* up to 2ulp error in [1,1.125] */

/* 2 <= x < 0x1p12 */

/* x >= 0x1p12 or x <= -2 or nan */


=== system/lib/libc/musl/src/math/acoshl.c ===
SHA256: 5831f9644f5fa531d90969c3386ca82e85bea97486d62c7bc8985a731d15df1f
Primary Git blob: 943cec17933551b6220043f4ac725084e51e9bde
/* acosh(x) = log(x + sqrt(x*x-1)) */

/* 0 <= x < 2, invalid if x < 1 */

/* 2 <= x < 0x1p32 */

/* x < 0 or x = -0, invalid */

/* 0x1p32 <= x or nan */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/acosl.c ===
SHA256: ed40b99c604aa593ee2ee71c02f928cb68c1afdf8a18243b0e7b6cc9a65586c1
Primary Git blob: c03bdf0235ccffd08ca26b603531a9defe11070a
/* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * See comments in acos.c.
 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
 */

/* |x| >= 1 or nan */

/* |x| < 0.5 */

/* x < -0.5 */

/* x > 0.5 */


=== system/lib/libc/musl/src/math/asin.c ===
SHA256: 9302dd0b2f302f7b7decce82e737ed250bae1bcc65c19eaf3d7ec19010892e63
Primary Git blob: c926b188552b20b1842a26e4c5500b2f0686a95f
/* origin: FreeBSD /usr/src/lib/msun/src/e_asin.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* asin(x)
 * Method :
 *      Since  asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
 *      we approximate asin(x) on [0,0.5] by
 *              asin(x) = x + x*x^2*R(x^2)
 *      where
 *              R(x^2) is a rational approximation of (asin(x)-x)/x^3
 *      and its remez error is bounded by
 *              |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
 *
 *      For x in [0.5,1]
 *              asin(x) = pi/2-2*asin(sqrt((1-x)/2))
 *      Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
 *      then for x>0.98
 *              asin(x) = pi/2 - 2*(s+s*z*R(z))
 *                      = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
 *      For x<=0.98, let pio4_hi = pio2_hi/2, then
 *              f = hi part of s;
 *              c = sqrt(z) - f = (z-f*f)/(s+f)         ...f+c=sqrt(z)
 *      and
 *              asin(x) = pi/2 - 2*(s+s*z*R(z))
 *                      = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
 *                      = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
 *
 * Special cases:
 *      if x is NaN, return x itself;
 *      if |x|>1, return NaN with invalid signal.
 *
 */

/* 0x3FF921FB, 0x54442D18 */

/* 0x3C91A626, 0x33145C07 */

/* coefficients for R(x^2) */

/* 0x3FC55555, 0x55555555 */

/* 0xBFD4D612, 0x03EB6F7D */

/* 0x3FC9C155, 0x0E884455 */

/* 0xBFA48228, 0xB5688F3B */

/* 0x3F49EFE0, 0x7501B288 */

/* 0x3F023DE1, 0x0DFDF709 */

/* 0xC0033A27, 0x1C8A2D4B */

/* 0x40002AE5, 0x9C598AC8 */

/* 0xBFE6066C, 0x1B8D0159 */

/* 0x3FB3B8C5, 0xB12E9282 */

/* |x| >= 1 or nan */

/* asin(1) = +-pi/2 with inexact */

/* |x| < 0.5 */

/* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */

/* 1 > |x| >= 0.5 */

/* if |x| > 0.975 */

/* f+c = sqrt(z) */


=== system/lib/libc/musl/src/math/asinf.c ===
SHA256: 6bc9b2392b81efa4c6a80c8602a2c0898d3b5c77444f6d3266ac71c18df222c5
Primary Git blob: bcd304a3425991689cbf14dd1cd575a43a8b1117
/* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* coefficients for R(x^2) */

/* |x| >= 1 */

/* |x| == 1 */

/* asin(+-1) = +-pi/2 with inexact */

/* asin(|x|>1) is NaN */

/* |x| < 0.5 */

/* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */

/* 1 > |x| >= 0.5 */


=== system/lib/libc/musl/src/math/asinh.c ===
SHA256: a0a31b87d1f7b11c43500602fc537097c7f59a483c27a82513944df0b1d6c4f3
Primary Git blob: 0829f228ef9d2540578c6512736c107b25c2bc06
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */

/* |x| */

/* |x| >= 0x1p26 or inf or nan */

/* |x| >= 2 */

/* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */

/* |x| < 0x1p-26, raise inexact if x != 0 */


=== system/lib/libc/musl/src/math/asinhf.c ===
SHA256: 86c6ccaf2da48664366fb876b4858564d780ab2e437d64a406b43ea0dffd4518
Primary Git blob: fc9f0911bf67fa1515234eeb4137142fadafab6e
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */

/* |x| */

/* |x| >= 0x1p12 or inf or nan */

/* |x| >= 2 */

/* |x| >= 0x1p-12, up to 1.6ulp error in [0.125,0.5] */

/* |x| < 0x1p-12, raise inexact if x!=0 */


=== system/lib/libc/musl/src/math/asinhl.c ===
SHA256: e7f4245e90efe3ca4fbbd20252b69194ef977eed49631311f43ec55e6499ea30
Primary Git blob: 8635f52e82381bdaff12badbd7cd170b2e05bf62
/* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */

/* |x| */

/* |x| >= 0x1p32 or inf or nan */

/* |x| >= 2 */

/* |x| >= 0x1p-32 */

/* |x| < 0x1p-32, raise inexact if x!=0 */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/asinl.c ===
SHA256: 4a0e729842b1bf3181bad43b2f048dd3652b73456e0a3f44f6e65c2c51765e9f
Primary Git blob: 347c53568cb11d787f91caaf21b2673e57b29da8
/* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * See comments in asin.c.
 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
 */

/* |x| >= 1 or nan */

/* asin(+-1)=+-pi/2 with inexact */

/* |x| < 0.5 */

/* return x with inexact if x!=0 */

/* 1 > |x| >= 0.5 */


=== system/lib/libc/musl/src/math/atan.c ===
SHA256: 1cffb67a65456ae0bc5f07a94df04a4f18ebc1ac0bffe3219250c4e0555ee01d
Primary Git blob: 63b0ab25e3cf02ea81bab5a9ee4d99d6c40bb582
/* origin: FreeBSD /usr/src/lib/msun/src/s_atan.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* atan(x)
 * Method
 *   1. Reduce x to positive by atan(x) = -atan(-x).
 *   2. According to the integer k=4t+0.25 chopped, t=x, the argument
 *      is further reduced to one of the following intervals and the
 *      arctangent of t is evaluated by the corresponding formula:
 *
 *      [0,7/16]      atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
 *      [7/16,11/16]  atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
 *      [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
 *      [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
 *      [39/16,INF]   atan(x) = atan(INF) + atan( -1/t )
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

/* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */

/* atan(1.0)hi 0x3FE921FB, 0x54442D18 */

/* atan(1.5)hi 0x3FEF730B, 0xD281F69B */

/* atan(inf)hi 0x3FF921FB, 0x54442D18 */

/* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */

/* atan(1.0)lo 0x3C81A626, 0x33145C07 */

/* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */

/* atan(inf)lo 0x3C91A626, 0x33145C07 */

/* 0x3FD55555, 0x5555550D */

/* 0xBFC99999, 0x9998EBC4 */

/* 0x3FC24924, 0x920083FF */

/* 0xBFBC71C6, 0xFE231671 */

/* 0x3FB745CD, 0xC54C206E */

/* 0xBFB3B0F2, 0xAF749A6D */

/* 0x3FB10D66, 0xA0D03D51 */

/* 0xBFADDE2D, 0x52DEFD9A */

/* 0x3FA97B4B, 0x24760DEB */

/* 0xBFA2B444, 0x2C6A6C2F */

/* 0x3F90AD3A, 0xE322DA11 */

/* if |x| >= 2^66 */

/* |x| < 0.4375 */

/* |x| < 2^-27 */

/* raise underflow for subnormal x */

/* |x| < 1.1875 */

/*  7/16 <= |x| < 11/16 */

/* 11/16 <= |x| < 19/16 */

/* |x| < 2.4375 */

/* 2.4375 <= |x| < 2^66 */

/* end of argument reduction */

/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */


=== system/lib/libc/musl/src/math/atan2.c ===
SHA256: a5f94b09b10b4e72bb15d94ae403c9dfd27d7ad881ecd729000004429acfca63
Primary Git blob: 5a1903c6240821b70e6993f3769563c5eb1ba18f
/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 */

/* atan2(y,x)
 * Method :
 *      1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
 *      2. Reduce x to positive by (if x and y are unexceptional):
 *              ARG (x+iy) = arctan(y/x)           ... if x > 0,
 *              ARG (x+iy) = pi - arctan[y/(-x)]   ... if x < 0,
 *
 * Special cases:
 *
 *      ATAN2((anything), NaN ) is NaN;
 *      ATAN2(NAN , (anything) ) is NaN;
 *      ATAN2(+-0, +(anything but NaN)) is +-0  ;
 *      ATAN2(+-0, -(anything but NaN)) is +-pi ;
 *      ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
 *      ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
 *      ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
 *      ATAN2(+-INF,+INF ) is +-pi/4 ;
 *      ATAN2(+-INF,-INF ) is +-3pi/4;
 *      ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

/* 0x400921FB, 0x54442D18 */

/* 0x3CA1A626, 0x33145C07 */

/* x = 1.0 */

/* 2*sign(x)+sign(y) */

/* when y = 0 */

/* atan(+-0,+anything)=+-0 */

/* atan(+0,-anything) = pi */

/* atan(-0,-anything) =-pi */

/* when x = 0 */

/* when x is INF */

/* atan(+INF,+INF) */

/* atan(-INF,+INF) */

/* atan(+INF,-INF) */

/* atan(-INF,-INF) */

/* atan(+...,+INF) */

/* atan(-...,+INF) */

/* atan(+...,-INF) */

/* atan(-...,-INF) */

/* |y/x| > 0x1p64 */

/* z = atan(|y/x|) without spurious underflow */

/* |y/x| < 0x1p-64, x<0 */

/* atan(+,+) */

/* atan(-,+) */

/* atan(+,-) */

/* case 3 */

/* atan(-,-) */


=== system/lib/libc/musl/src/math/atan2f.c ===
SHA256: 31a61a0a4c7b00db625b708525f24673a83df868a3e363042c9cc9dcf0aaeec8
Primary Git blob: c634d00fc93195f63d25b59c0ae6e4a0e8e826d2
/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2f.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x40490fdb */

/* 0xb3bbbd2e */

/* x=1.0 */

/* 2*sign(x)+sign(y) */

/* when y = 0 */

/* atan(+-0,+anything)=+-0 */

/* atan(+0,-anything) = pi */

/* atan(-0,-anything) =-pi */

/* when x = 0 */

/* when x is INF */

/* atan(+INF,+INF) */

/* atan(-INF,+INF) */

/*atan(+INF,-INF)*/

/*atan(-INF,-INF)*/

/* atan(+...,+INF) */

/* atan(-...,+INF) */

/* atan(+...,-INF) */

/* atan(-...,-INF) */

/* |y/x| > 0x1p26 */

/* z = atan(|y/x|) with correct underflow */

/*|y/x| < 0x1p-26, x < 0 */

/* atan(+,+) */

/* atan(-,+) */

/* atan(+,-) */

/* case 3 */

/* atan(-,-) */


=== system/lib/libc/musl/src/math/atan2l.c ===
SHA256: c13d4d9e1329ffcbbf3ef1dd755602c771612f2dd98f38464fc9fb0f7bdf3c68
Primary Git blob: f0937a9794986068b712972342a28fb3500333fa
/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 */

/*
 * See comments in atan2.c.
 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
 */

/* atan(+-0,+anything)=+-0 */

/* atan(+0,-anything) = pi */

/* atan(-0,-anything) =-pi */

/* atan(+INF,+INF) */

/* atan(-INF,+INF) */

/* atan(+INF,-INF) */

/* atan(-INF,-INF) */

/* atan(+...,+INF) */

/* atan(-...,+INF) */

/* atan(+...,-INF) */

/* atan(-...,-INF) */

/* z = atan(|y/x|) without spurious underflow */

/* |y/x| < 0x1p-120, x<0 */

/* atan(+,+) */

/* atan(-,+) */

/* atan(+,-) */

/* case 3 */

/* atan(-,-) */


=== system/lib/libc/musl/src/math/atanf.c ===
SHA256: e0533d7b72aabce311a758a1f94fd15e5d4067be73b716cb1f425df5bc9039d6
Primary Git blob: 178341b670fa249fa50157d878ac2a66bd7f1843
/* origin: FreeBSD /usr/src/lib/msun/src/s_atanf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* atan(0.5)hi 0x3eed6338 */

/* atan(1.0)hi 0x3f490fda */

/* atan(1.5)hi 0x3f7b985e */

/* atan(inf)hi 0x3fc90fda */

/* atan(0.5)lo 0x31ac3769 */

/* atan(1.0)lo 0x33222168 */

/* atan(1.5)lo 0x33140fb4 */

/* atan(inf)lo 0x33a22168 */

/* if |x| >= 2**26 */

/* |x| < 0.4375 */

/* |x| < 2**-12 */

/* raise underflow for subnormal x */

/* |x| < 1.1875 */

/*  7/16 <= |x| < 11/16 */

/* 11/16 <= |x| < 19/16 */

/* |x| < 2.4375 */

/* 2.4375 <= |x| < 2**26 */

/* end of argument reduction */

/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */


=== system/lib/libc/musl/src/math/atanh.c ===
SHA256: 1bfda6f427e5cb7e350cfc2ab08e022968f5d13e9728d35cbe7d601e9977d44f
Primary Git blob: 63a035d7063ae2d5df2c31728e10e5d471209c79
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */

/* |x| */

/* handle underflow */

/* |x| < 0.5, up to 1.7ulp error */

/* avoid overflow */


=== system/lib/libc/musl/src/math/atanhf.c ===
SHA256: 3de72682dc18817fcc3b521d574cbe5a0f3c01af371ca4ccb2fd1bc3441b359a
Primary Git blob: 65f07c0f4f26e302f98ee4cc75b471c4204ee829
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */

/* |x| */

/* handle underflow */

/* |x| < 0.5, up to 1.7ulp error */

/* avoid overflow */


=== system/lib/libc/musl/src/math/atanhl.c ===
SHA256: d8a07b1833be974874ccae06f105f1bc00ad39efd9e5a62410abe4d3f6893c05
Primary Git blob: 87cd1cdb5f325f01cf12d19594efbcead93472b1
/* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */

/* |x| */

/* handle underflow */

/* |x| < 0.5, up to 1.7ulp error */

/* avoid overflow */


=== system/lib/libc/musl/src/math/atanl.c ===
SHA256: 5c6f655740e6f594db8a045e529582f20613d14ac2bca8bf3f881145bf459325
Primary Git blob: c3b0c9268db309060614a94e11d3755e2d26110a
/* origin: FreeBSD /usr/src/lib/msun/src/s_atanl.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * See comments in atan.c.
 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
 */

/* if |x| is large, atan(x)~=pi/2 */

/* Extract the exponent and the first few bits of the mantissa. */

/* |x| < 0.4375 */

/* if |x| is small, atanl(x)~=x */

/* raise underflow if subnormal */

/* |x| < 1.1875 */

/*  7/16 <= |x| < 11/16 */

/* 11/16 <= |x| < 19/16 */

/* |x| < 2.4375 */

/* 2.4375 <= |x| */

/* end of argument reduction */

/* break sum aT[i]z**(i+1) into odd and even poly */


=== system/lib/libc/musl/src/math/cbrt.c ===
SHA256: af442893d4048c0eb485b93b5628792fb796d45ffc0f88c682041366c7da611d
Primary Git blob: 7599d3e37d2f6f81f21321b62f1e97aae5e34167
/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrt.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 * Optimized by Bruce D. Evans.
 */

/* cbrt(x)
 * Return cube root of x
 */

/* B1 = (1023-1023/3-0.03306235651)*2**20 */

/* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */

/* |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]). */

/* 0x3ffe03e6, 0x0f61e692 */

/* 0xbffe28e0, 0x92f02420 */

/* 0x3ff9f160, 0x4a49d6c2 */

/* 0xbfe844cb, 0xbee751d9 */

/* 0x3fc2b000, 0xd4e4edd7 */

/* cbrt(NaN,INF) is itself */

/*
	 * Rough cbrt to 5 bits:
	 *    cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3)
	 * where e is integral and >= 0, m is real and in [0, 1), and "/" and
	 * "%" are integer division and modulus with rounding towards minus
	 * infinity.  The RHS is always >= the LHS and has a maximum relative
	 * error of about 1 in 16.  Adding a bias of -0.03306235651 to the
	 * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE
	 * floating point representation, for finite positive normal values,
	 * ordinary integer divison of the value in bits magically gives
	 * almost exactly the RHS of the above provided we first subtract the
	 * exponent bias (1023 for doubles) and later add it back.  We do the
	 * subtraction virtually to keep e >= 0 so that ordinary integer
	 * division rounds towards minus infinity; this is also efficient.
	 */

/* zero or subnormal? */

/* cbrt(0) is itself */

/*
	 * New cbrt to 23 bits:
	 *    cbrt(x) = t*cbrt(x/t**3) ~= t*P(t**3/x)
	 * where P(r) is a polynomial of degree 4 that approximates 1/cbrt(r)
	 * to within 2**-23.5 when |r - 1| < 1/10.  The rough approximation
	 * has produced t such than |t/cbrt(x) - 1| ~< 1/32, and cubing this
	 * gives us bounds for r = t**3/x.
	 *
	 * Try to optimize for parallel evaluation as in __tanf.c.
	 */

/*
	 * Round t away from zero to 23 bits (sloppily except for ensuring that
	 * the result is larger in magnitude than cbrt(x) but not much more than
	 * 2 23-bit ulps larger).  With rounding towards zero, the error bound
	 * would be ~5/6 instead of ~4/6.  With a maximum error of 2 23-bit ulps
	 * in the rounded t, the infinite-precision error in the Newton
	 * approximation barely affects third digit in the final error
	 * 0.667; the error in the rounded t can be up to about 3 23-bit ulps
	 * before the final error is larger than 0.667 ulps.
	 */

/* one step Newton iteration to 53 bits with error < 0.667 ulps */

/* t*t is exact */

/* error <= 0.5 ulps; |r| < |t| */

/* t+t is exact */

/* r-t is exact; w+r ~= 3*t */

/* error <= 0.5 + 0.5/3 + epsilon */


=== system/lib/libc/musl/src/math/cbrtf.c ===
SHA256: 87b7065f44ac0cef6d21385c2b453dde7e15a51e9008ae0d726cd9eaa2dc43da
Primary Git blob: 89c2c8655da46a37a737dfed63ae8c619f9c7350
/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Debugged and optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* cbrtf(x)
 * Return cube root of x
 */

/* B1 = (127-127.0/3-0.03306235651)*2**23 */

/* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */

/* cbrt(NaN,INF) is itself */

/* rough cbrt to 5 bits */

/* zero or subnormal? */

/* cbrt(+-0) is itself */

/*
	 * First step Newton iteration (solving t*t-x/t == 0) to 16 bits.  In
	 * double precision so that its terms can be arranged for efficiency
	 * without causing overflow or underflow.
	 */

/*
	 * Second step Newton iteration to 47 bits.  In double precision for
	 * efficiency and accuracy.
	 */

/* rounding to 24 bits is perfect in round-to-nearest mode */


=== system/lib/libc/musl/src/math/cbrtl.c ===
SHA256: ee82c17b1a24681dfd7de0161088b45ecbd2d0346ddeda9d4594b48e4da0d3e5
Primary Git blob: ceff9136ebb507a604688ce07f3e6eae0fcd888c
/* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtl.c */

/*-
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 * Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 * The argument reduction and testing for exceptional cases was
 * written by Steven G. Kargl with input from Bruce D. Evans
 * and David A. Schultz.
 */

/* B1 = (127-127.0/3-0.03306235651)*2**23 */

/*
	 * If x = +-Inf, then cbrt(x) = +-Inf.
	 * If x = NaN, then cbrt(x) = NaN.
	 */

/* Adjust subnormal numbers. */

/* If x = +-0, then cbrt(x) = +-0. */

/*
	 * The following is the guts of s_cbrtf, with the handling of
	 * special values removed and extra care for accuracy not taken,
	 * but with most of the extra accuracy not discarded.
	 */

/* ~5-bit estimate: */

/* ~16-bit estimate: */

/* ~47-bit estimate: */

/*
	 * dt is cbrtl(x) to ~47 bits (after x has been reduced to 1 <= x < 8).
	 * Round it away from zero to 32 bits (32 so that t*t is exact, and
	 * away from zero for technical reasons).
	 */

/*
	 * Round dt away from zero to 47 bits.  Since we don't trust the 47,
	 * add 2 47-bit ulps instead of 1 to round up.  Rounding is slow and
	 * might be avoidable in this case, since on most machines dt will
	 * have been evaluated in 53-bit precision and the technical reasons
	 * for rounding up might not apply to either case in cbrtl() since
	 * dt is much more accurate than needed.
	 */

/*
	 * Final step Newton iteration to 64 or 113 bits with
	 * error < 0.667 ulps
	 */

/* t*t is exact */

/* error <= 0.5 ulps; |r| < |t| */

/* t+t is exact */

/* r-t is exact; w+r ~= 3*t */

/* error <= 0.5 + 0.5/3 + epsilon */


=== system/lib/libc/musl/src/math/ceil.c ===
SHA256: 20eedc885a3a8af0838b35795bba0c47371fa7b8babe5f5ff41013004acec41d
Primary Git blob: 93265657d3585647068bdcfae4c3f9dd4da25d66
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236

/* y = int(x) - x, where int(x) is an integer neighbor of x */

/* special case because of non-nearest rounding modes */


=== system/lib/libc/musl/src/math/ceilf.c ===
SHA256: 25b575e8865867a405530e2429da4c48d59203375b36ec007057788dbe65588f
Primary Git blob: 9a071337029a74ca919df7f7e3751d0930282321
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/ceill.c ===
SHA256: fd18da5d5f7ee0dc80b8fd6570ebd108572ae310c20dd9ab273514742479ed53
Primary Git blob: 60a83020dd1cb6f6764d0ddb5b64ba9476e71d15
/* y = int(x) - x, where int(x) is an integer neighbor of x */

/* special case because of non-nearest rounding modes */


=== system/lib/libc/musl/src/math/copysign.c ===
SHA256: 4ebd1f5161d32e379b0545d423cd2065c6ead6bd9334810901d971ebcd3822c0
Primary Git blob: 1fc78c9f23ad122fd64d19a07251958b5ee49a23
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/copysignf.c ===
SHA256: 8fc8d5938575438c73320038d5b6612f33e7b130f72e3f39db1e68d994276b93
Primary Git blob: 76d2d255dcf828fdd8aa9839312f476377ff0f20
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/cos.c ===
SHA256: 3a74e054057d636fa494bdd76a53a40db5cee618264f6ab31cb0538ba63c6bda
Primary Git blob: ee97f68bbb7be73e473e9324484bed533fcb39bb
/* origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* cos(x)
 * Return cosine function of x.
 *
 * kernel function:
 *      __sin           ... sine function on [-pi/4,pi/4]
 *      __cos           ... cosine function on [-pi/4,pi/4]
 *      __rem_pio2      ... argument reduction routine
 *
 * Method.
 *      Let S,C and T denote the sin, cos and tan respectively on
 *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
 *      in [-pi/4 , +pi/4], and let n = k mod 4.
 *      We have
 *
 *          n        sin(x)      cos(x)        tan(x)
 *     ----------------------------------------------------------
 *          0          S           C             T
 *          1          C          -S            -1/T
 *          2         -S          -C             T
 *          3         -C           S            -1/T
 *     ----------------------------------------------------------
 *
 * Special cases:
 *      Let trig be any of sin, cos, or tan.
 *      trig(+-INF)  is NaN, with signals;
 *      trig(NaN)    is that NaN;
 *
 * Accuracy:
 *      TRIG(x) returns trig(x) nearly rounded
 */

/* |x| ~< pi/4 */

/* |x| < 2**-27 * sqrt(2) */

/* raise inexact if x!=0 */

/* cos(Inf or NaN) is NaN */

/* argument reduction */


=== system/lib/libc/musl/src/math/cosf.c ===
SHA256: 33cf828e8e733da2b72c723b9ff20057b9a4f10df72a3923dadcb626c23d222c
Primary Git blob: 23f3e5bf69f29e3177035c0368f8778e2fc50ce1
/* origin: FreeBSD /usr/src/lib/msun/src/s_cosf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* Small multiples of pi/2 rounded to double precision. */

/* 0x3FF921FB, 0x54442D18 */

/* 0x400921FB, 0x54442D18 */

/* 0x4012D97C, 0x7F3321D2 */

/* 0x401921FB, 0x54442D18 */

/* |x| ~<= pi/4 */

/* |x| < 2**-12 */

/* raise inexact if x != 0 */

/* |x| ~<= 5*pi/4 */

/* |x|  ~> 3*pi/4 */

/* |x| ~<= 9*pi/4 */

/* |x| ~> 7*pi/4 */

/* cos(Inf or NaN) is NaN */

/* general argument reduction needed */


=== system/lib/libc/musl/src/math/cosh.c ===
SHA256: 5e5ed87e1a80e68734f4c87a4907a55f50a54df58261698aa94d5cb3276a3d43
Primary Git blob: 490c15fb166752d18fa4015401f5a27fd34337b6
/* cosh(x) = (exp(x) + 1/exp(x))/2
 *         = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x)
 *         = 1 + x*x/2 + o(x^4)
 */

/* |x| */

/* |x| < log(2) */

/* raise inexact if x!=0 */

/* |x| < log(DBL_MAX) */

/* note: if x>log(0x1p26) then the 1/t is not needed */

/* |x| > log(DBL_MAX) or nan */

/* note: the result is stored to handle overflow */


=== system/lib/libc/musl/src/math/coshf.c ===
SHA256: c834656b0af1d4055167badf60afb062b4d71385a7d5a44769d1039bb9417b7c
Primary Git blob: e739cff93b1325f931198d8d75b3313359803752
/* |x| */

/* |x| < log(2) */

/* |x| < log(FLT_MAX) */

/* |x| > log(FLT_MAX) or nan */


=== system/lib/libc/musl/src/math/coshl.c ===
SHA256: dae73b174c81e48fd3db2403f5293ff791c822a071a18d8f85c3aaac1e220f65
Primary Git blob: 06a56fe3be85d346cd98de913c091e900046a938
/* |x| */

/* |x| < log(2) */

/* |x| < log(LDBL_MAX) */

/* |x| > log(LDBL_MAX) or nan */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/cosl.c ===
SHA256: 35e7b531fb8d836960bcd41cd5d8f6dbfce9a35c050828c4fe171c2e0816ec15
Primary Git blob: 79c41c77fa6a0addc57e33c62f31d879392b36e6
/* raise inexact if x!=0 */


=== system/lib/libc/musl/src/math/erf.c ===
SHA256: 795f05c9388ac277ab27cb5dc63fb4f82620a0ee11eaf8403201df5bc65c0f5b
Primary Git blob: 2f30a298f997cde0316af8681bb1447f085de54d
/* origin: FreeBSD /usr/src/lib/msun/src/s_erf.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* double erf(double x)
 * double erfc(double x)
 *                           x
 *                    2      |\
 *     erf(x)  =  ---------  | exp(-t*t)dt
 *                 sqrt(pi) \|
 *                           0
 *
 *     erfc(x) =  1-erf(x)
 *  Note that
 *              erf(-x) = -erf(x)
 *              erfc(-x) = 2 - erfc(x)
 *
 * Method:
 *      1. For |x| in [0, 0.84375]
 *          erf(x)  = x + x*R(x^2)
 *          erfc(x) = 1 - erf(x)           if x in [-.84375,0.25]
 *                  = 0.5 + ((0.5-x)-x*R)  if x in [0.25,0.84375]
 *         where R = P/Q where P is an odd poly of degree 8 and
 *         Q is an odd poly of degree 10.
 *                                               -57.90
 *                      | R - (erf(x)-x)/x | <= 2
 *
 *
 *         Remark. The formula is derived by noting
 *          erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....)
 *         and that
 *          2/sqrt(pi) = 1.128379167095512573896158903121545171688
 *         is close to one. The interval is chosen because the fix
 *         point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is
 *         near 0.6174), and by some experiment, 0.84375 is chosen to
 *         guarantee the error is less than one ulp for erf.
 *
 *      2. For |x| in [0.84375,1.25], let s = |x| - 1, and
 *         c = 0.84506291151 rounded to single (24 bits)
 *              erf(x)  = sign(x) * (c  + P1(s)/Q1(s))
 *              erfc(x) = (1-c)  - P1(s)/Q1(s) if x > 0
 *                        1+(c+P1(s)/Q1(s))    if x < 0
 *              |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06
 *         Remark: here we use the taylor series expansion at x=1.
 *              erf(1+s) = erf(1) + s*Poly(s)
 *                       = 0.845.. + P1(s)/Q1(s)
 *         That is, we use rational approximation to approximate
 *                      erf(1+s) - (c = (single)0.84506291151)
 *         Note that |P1/Q1|< 0.078 for x in [0.84375,1.25]
 *         where
 *              P1(s) = degree 6 poly in s
 *              Q1(s) = degree 6 poly in s
 *
 *      3. For x in [1.25,1/0.35(~2.857143)],
 *              erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1)
 *              erf(x)  = 1 - erfc(x)
 *         where
 *              R1(z) = degree 7 poly in z, (z=1/x^2)
 *              S1(z) = degree 8 poly in z
 *
 *      4. For x in [1/0.35,28]
 *              erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0
 *                      = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0
 *                      = 2.0 - tiny            (if x <= -6)
 *              erf(x)  = sign(x)*(1.0 - erfc(x)) if x < 6, else
 *              erf(x)  = sign(x)*(1.0 - tiny)
 *         where
 *              R2(z) = degree 6 poly in z, (z=1/x^2)
 *              S2(z) = degree 7 poly in z
 *
 *      Note1:
 *         To compute exp(-x*x-0.5625+R/S), let s be a single
 *         precision number and s := x; then
 *              -x*x = -s*s + (s-x)*(s+x)
 *              exp(-x*x-0.5626+R/S) =
 *                      exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S);
 *      Note2:
 *         Here 4 and 5 make use of the asymptotic series
 *                        exp(-x*x)
 *              erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) )
 *                        x*sqrt(pi)
 *         We use rational approximation to approximate
 *              g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625
 *         Here is the error bound for R1/S1 and R2/S2
 *              |R1/S1 - f(x)|  < 2**(-62.57)
 *              |R2/S2 - f(x)|  < 2**(-61.52)
 *
 *      5. For inf > x >= 28
 *              erf(x)  = sign(x) *(1 - tiny)  (raise inexact)
 *              erfc(x) = tiny*tiny (raise underflow) if x > 0
 *                      = 2 - tiny if x<0
 *
 *      7. Special case:
 *              erf(0)  = 0, erf(inf)  = 1, erf(-inf) = -1,
 *              erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2,
 *              erfc/erf(NaN) is NaN
 */

/* 0x3FEB0AC1, 0x60000000 */

/*
 * Coefficients for approximation to  erf on [0,0.84375]
 */

/* 0x3FF06EBA, 0x8214DB69 */

/* 0x3FC06EBA, 0x8214DB68 */

/* 0xBFD4CD7D, 0x691CB913 */

/* 0xBF9D2A51, 0xDBD7194F */

/* 0xBF77A291, 0x236668E4 */

/* 0xBEF8EAD6, 0x120016AC */

/* 0x3FD97779, 0xCDDADC09 */

/* 0x3FB0A54C, 0x5536CEBA */

/* 0x3F74D022, 0xC4D36B0F */

/* 0x3F215DC9, 0x221C1A10 */

/* 0xBED09C43, 0x42A26120 */

/*
 * Coefficients for approximation to  erf  in [0.84375,1.25]
 */

/* 0xBF6359B8, 0xBEF77538 */

/* 0x3FDA8D00, 0xAD92B34D */

/* 0xBFD7D240, 0xFBB8C3F1 */

/* 0x3FD45FCA, 0x805120E4 */

/* 0xBFBC6398, 0x3D3E28EC */

/* 0x3FA22A36, 0x599795EB */

/* 0xBF61BF38, 0x0A96073F */

/* 0x3FBB3E66, 0x18EEE323 */

/* 0x3FE14AF0, 0x92EB6F33 */

/* 0x3FB2635C, 0xD99FE9A7 */

/* 0x3FC02660, 0xE763351F */

/* 0x3F8BEDC2, 0x6B51DD1C */

/* 0x3F888B54, 0x5735151D */

/*
 * Coefficients for approximation to  erfc in [1.25,1/0.35]
 */

/* 0xBF843412, 0x600D6435 */

/* 0xBFE63416, 0xE4BA7360 */

/* 0xC0251E04, 0x41B0E726 */

/* 0xC04F300A, 0xE4CBA38D */

/* 0xC0644CB1, 0x84282266 */

/* 0xC067135C, 0xEBCCABB2 */

/* 0xC0545265, 0x57E4D2F2 */

/* 0xC023A0EF, 0xC69AC25C */

/* 0x4033A6B9, 0xBD707687 */

/* 0x4061350C, 0x526AE721 */

/* 0x407B290D, 0xD58A1A71 */

/* 0x40842B19, 0x21EC2868 */

/* 0x407AD021, 0x57700314 */

/* 0x405B28A3, 0xEE48AE2C */

/* 0x401A47EF, 0x8E484A93 */

/* 0xBFAEEFF2, 0xEE749A62 */

/*
 * Coefficients for approximation to  erfc in [1/.35,28]
 */

/* 0xBF843412, 0x39E86F4A */

/* 0xBFE993BA, 0x70C285DE */

/* 0xC031C209, 0x555F995A */

/* 0xC064145D, 0x43C5ED98 */

/* 0xC083EC88, 0x1375F228 */

/* 0xC0900461, 0x6A2E5992 */

/* 0xC07E384E, 0x9BDC383F */

/* 0x403E568B, 0x261D5190 */

/* 0x40745CAE, 0x221B9F0A */

/* 0x409802EB, 0x189D5118 */

/* 0x40A8FFB7, 0x688C246A */

/* 0x40A3F219, 0xCEDF3BE6 */

/* 0x407DA874, 0xE79FE763 */

/* 0xC03670E2, 0x42712D62 */

/* |x| < 1.25 */

/* |x| < 1/.35 ~ 2.85714 */

/* |x| > 1/.35 */

/* erf(nan)=nan, erf(+-inf)=+-1 */

/* |x| < 0.84375 */

/* |x| < 2**-28 */

/* avoid underflow */

/* 0.84375 <= |x| < 6 */

/* erfc(nan)=nan, erfc(+-inf)=0,2 */

/* |x| < 0.84375 */

/* |x| < 2**-56 */

/* x < 1/4 */

/* 0.84375 <= |x| < 28 */


=== system/lib/libc/musl/src/math/erff.c ===
SHA256: 876ad823d25e58330628ccdc5d24a3f10cc255135046a4e2903daf33cb75c18f
Primary Git blob: ed5f3975741595057cbc981d13fd6c43ce11270a
/* origin: FreeBSD /usr/src/lib/msun/src/s_erff.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x3f58560b */

/*
 * Coefficients for approximation to  erf on [0,0.84375]
 */

/* 0x3f8375d4 */

/* 0x3e0375d4 */

/* 0xbea66beb */

/* 0xbce9528f */

/* 0xbbbd1489 */

/* 0xb7c756b1 */

/* 0x3ecbbbce */

/* 0x3d852a63 */

/* 0x3ba68116 */

/* 0x390aee49 */

/* 0xb684e21a */

/*
 * Coefficients for approximation to  erf  in [0.84375,1.25]
 */

/* 0xbb1acdc6 */

/* 0x3ed46805 */

/* 0xbebe9208 */

/* 0x3ea2fe54 */

/* 0xbde31cc2 */

/* 0x3d1151b3 */

/* 0xbb0df9c0 */

/* 0x3dd9f331 */

/* 0x3f0a5785 */

/* 0x3d931ae7 */

/* 0x3e013307 */

/* 0x3c5f6e13 */

/* 0x3c445aa3 */

/*
 * Coefficients for approximation to  erfc in [1.25,1/0.35]
 */

/* 0xbc21a093 */

/* 0xbf31a0b7 */

/* 0xc128f022 */

/* 0xc2798057 */

/* 0xc322658c */

/* 0xc3389ae7 */

/* 0xc2a2932b */

/* 0xc11d077e */

/* 0x419d35ce */

/* 0x4309a863 */

/* 0x43d9486f */

/* 0x442158c9 */

/* 0x43d6810b */

/* 0x42d9451f */

/* 0x40d23f7c */

/* 0xbd777f97 */

/*
 * Coefficients for approximation to  erfc in [1/.35,28]
 */

/* 0xbc21a092 */

/* 0xbf4c9dd4 */

/* 0xc18e104b */

/* 0xc320a2ea */

/* 0xc41f6441 */

/* 0xc480230b */

/* 0xc3f1c275 */

/* 0x41f2b459 */

/* 0x43a2e571 */

/* 0x44c01759 */

/* 0x4547fdbb */

/* 0x451f90ce */

/* 0x43ed43a7 */

/* 0xc1b38712 */

/* |x| < 1.25 */

/* |x| < 1/0.35 */

/* |x| >= 1/0.35 */

/* erf(nan)=nan, erf(+-inf)=+-1 */

/* |x| < 0.84375 */

/* |x| < 2**-28 */

/*avoid underflow */

/* |x| < 6 */

/* erfc(nan)=nan, erfc(+-inf)=0,2 */

/* |x| < 0.84375 */

/* |x| < 2**-56 */

/* x < 1/4 */

/* |x| < 28 */


=== system/lib/libc/musl/src/math/erfl.c ===
SHA256: dcce5b86a37215aee265ae27c1a00526542ab13d1dd609a560de3e3e9049a3e6
Primary Git blob: e267c231059cb85c126b8e86a10d43254ff5aaf0
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_erfl.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* double erf(double x)
 * double erfc(double x)
 *                           x
 *                    2      |\
 *     erf(x)  =  ---------  | exp(-t*t)dt
 *                 sqrt(pi) \|
 *                           0
 *
 *     erfc(x) =  1-erf(x)
 *  Note that
 *              erf(-x) = -erf(x)
 *              erfc(-x) = 2 - erfc(x)
 *
 * Method:
 *      1. For |x| in [0, 0.84375]
 *          erf(x)  = x + x*R(x^2)
 *          erfc(x) = 1 - erf(x)           if x in [-.84375,0.25]
 *                  = 0.5 + ((0.5-x)-x*R)  if x in [0.25,0.84375]
 *         Remark. The formula is derived by noting
 *          erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....)
 *         and that
 *          2/sqrt(pi) = 1.128379167095512573896158903121545171688
 *         is close to one. The interval is chosen because the fix
 *         point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is
 *         near 0.6174), and by some experiment, 0.84375 is chosen to
 *         guarantee the error is less than one ulp for erf.
 *
 *      2. For |x| in [0.84375,1.25], let s = |x| - 1, and
 *         c = 0.84506291151 rounded to single (24 bits)
 *      erf(x)  = sign(x) * (c  + P1(s)/Q1(s))
 *      erfc(x) = (1-c)  - P1(s)/Q1(s) if x > 0
 *                        1+(c+P1(s)/Q1(s))    if x < 0
 *         Remark: here we use the taylor series expansion at x=1.
 *              erf(1+s) = erf(1) + s*Poly(s)
 *                       = 0.845.. + P1(s)/Q1(s)
 *         Note that |P1/Q1|< 0.078 for x in [0.84375,1.25]
 *
 *      3. For x in [1.25,1/0.35(~2.857143)],
 *      erfc(x) = (1/x)*exp(-x*x-0.5625+R1(z)/S1(z))
 *              z=1/x^2
 *      erf(x)  = 1 - erfc(x)
 *
 *      4. For x in [1/0.35,107]
 *      erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0
 *                      = 2.0 - (1/x)*exp(-x*x-0.5625+R2(z)/S2(z))
 *                             if -6.666<x<0
 *                      = 2.0 - tiny            (if x <= -6.666)
 *              z=1/x^2
 *      erf(x)  = sign(x)*(1.0 - erfc(x)) if x < 6.666, else
 *      erf(x)  = sign(x)*(1.0 - tiny)
 *      Note1:
 *         To compute exp(-x*x-0.5625+R/S), let s be a single
 *         precision number and s := x; then
 *              -x*x = -s*s + (s-x)*(s+x)
 *              exp(-x*x-0.5626+R/S) =
 *                      exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S);
 *      Note2:
 *         Here 4 and 5 make use of the asymptotic series
 *                        exp(-x*x)
 *              erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) )
 *                        x*sqrt(pi)
 *
 *      5. For inf > x >= 107
 *      erf(x)  = sign(x) *(1 - tiny)  (raise inexact)
 *      erfc(x) = tiny*tiny (raise underflow) if x > 0
 *                      = 2 - tiny if x<0
 *
 *      7. Special case:
 *      erf(0)  = 0, erf(inf)  = 1, erf(-inf) = -1,
 *      erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2,
 *              erfc/erf(NaN) is NaN
 */

/*
 * Coefficients for approximation to  erf on [0,0.84375]
 */

/* 8 * (2/sqrt(pi) - 1) */

/* 1.000000000000000000000000000000000000000E0 */

/*
 * Coefficients for approximation to  erf  in [0.84375,1.25]
 */

/* erf(x+1) = 0.845062911510467529296875 + pa(x)/qa(x)
   -0.15625 <= x <= +.25
   Peak relative error 8.5e-22  */

/* 1.000000000000000000000000000000000000000E0 */

/*
 * Coefficients for approximation to  erfc in [1.25,1/0.35]
 */

/* erfc(1/x) = x exp (-1/x^2 - 0.5625 + ra(x^2)/sa(x^2))
   1/2.85711669921875 < 1/x < 1/1.25
   Peak relative error 3.1e-21  */

/* 1.000000000000000000000000000000000000000E0 */

/*
 * Coefficients for approximation to  erfc in [1/.35,107]
 */

/* erfc(1/x) = x exp (-1/x^2 - 0.5625 + rb(x^2)/sb(x^2))
   1/6.6666259765625 < 1/x < 1/2.85711669921875
   Peak relative error 4.2e-22  */

/* 1.000000000000000000000000000000000000000E0 */

/* erfc(1/x) = x exp (-1/x^2 - 0.5625 + rc(x^2)/sc(x^2))
   1/107 <= 1/x <= 1/6.6666259765625
   Peak relative error 1.1e-21  */

/* 1.000000000000000000000000000000000000000E0 */

/* 0.84375 <= |x| < 1.25 */

/* 1.25 <= |x| < 2.857 ~ 1/.35 */

/* 2.857 <= |x| < 6.6666259765625 */

/* 6.666 <= |x| < 107 (erfc only) */

/* erf(nan)=nan, erf(+-inf)=+-1 */

/* |x| < 0.84375 */

/* |x| < 2**-33 */

/* avoid underflow */

/* |x| < 6.6666259765625 */

/* erfc(nan) = nan, erfc(+-inf) = 0,2 */

/* |x| < 0.84375 */

/* |x| < 2**-65 */

/* x < 1/4 */

/* |x| < 107 */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/exp.c ===
SHA256: 7db56f21ca9b8915d36dd5099b707aafeb6a736eae798e19b76b074764e75f34
Primary Git blob: b764d73cfe339c22579d28388b387ba22ba7eda0
/*
 * Double-precision e^x function.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* Handle cases that may overflow or underflow when computing the result that
   is scale*(1+TMP) without intermediate rounding.  The bit representation of
   scale is in SBITS, however it has a computed exponent that may have
   overflown into the sign bit so that needs to be adjusted before using it as
   a double.  (int32_t)KI is the k used in the argument reduction and exponent
   adjustment of scale, positive k here means the result may overflow and
   negative k means the result may underflow.  */

/* k > 0, the exponent of scale might have overflowed by <= 460.  */

/* k < 0, need special care in the subnormal range.  */

/* Round y to the right precision before scaling it into the subnormal
		 range to avoid double rounding that can cause 0.5+E/2 ulp error where
		 E is the worst-case ulp error outside the subnormal range.  So this
		 is only useful if the goal is better than 1 ulp worst-case error.  */

/* Avoid -0.0 with downward rounding.  */

/* The underflow exception needs to be signaled explicitly.  */

/* Top 12 bits of a double (sign and exponent bits).  */

/* Avoid spurious underflow for tiny x.  */

/* Note: 0 is common input.  */

/* Large x is special cased below.  */

/* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].  */

/* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].  */

/* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.  */

/* z - kd is in [-1, 1] in non-nearest rounding modes.  */

/* 2^(k/N) ~= scale * (1 + tail).  */

/* This is only a valid scale when -1023*N < k < 1024*N.  */

/* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).  */

/* Evaluation is optimized assuming superscalar pipelined execution.  */

/* Without fma the worst case error is 0.25/N ulp larger.  */

/* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.  */

/* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
	   is no spurious underflow here even without fma.  */


=== system/lib/libc/musl/src/math/exp10.c ===
SHA256: a489cd8fbe2406ea2ccdc00cfccfecc529e9904061082dd9183aee8192be33cd
Primary Git blob: 26899ebac90e1a094d422efcd01806e5cc31e53f
/* fabs(n) < 16 without raising invalid on nan */


=== system/lib/libc/musl/src/math/exp10f.c ===
SHA256: 9dba65dc30153819eb30cdcaf8d37eb9b3d222777da0c6844ec4d59e78ae13df
Primary Git blob: d009f0a84fdd9f15010ee83de729b86e50f69caf
/* fabsf(n) < 8 without raising invalid on nan */


=== system/lib/libc/musl/src/math/exp10l.c ===
SHA256: 79085a74790fd49e4aa30e4611d1dd31224e33b8d9d0dbd229a34e842d2e7806
Primary Git blob: f3da1a082c5ef35183304ed12f7c74d7d168db1d
/* fabsl(n) < 16 without raising invalid on nan */


=== system/lib/libc/musl/src/math/exp2.c ===
SHA256: b771de769e1b69b931d1f95baa39b429a73c9904e8b5607e1736771c6ace92b1
Primary Git blob: e0ff54bd85bb4a8372a13d26516aa859e6adaf42
/*
 * Double-precision 2^x function.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* Handle cases that may overflow or underflow when computing the result that
   is scale*(1+TMP) without intermediate rounding.  The bit representation of
   scale is in SBITS, however it has a computed exponent that may have
   overflown into the sign bit so that needs to be adjusted before using it as
   a double.  (int32_t)KI is the k used in the argument reduction and exponent
   adjustment of scale, positive k here means the result may overflow and
   negative k means the result may underflow.  */

/* k > 0, the exponent of scale might have overflowed by 1.  */

/* k < 0, need special care in the subnormal range.  */

/* Round y to the right precision before scaling it into the subnormal
		   range to avoid double rounding that can cause 0.5+E/2 ulp error where
		   E is the worst-case ulp error outside the subnormal range.  So this
		   is only useful if the goal is better than 1 ulp worst-case error.  */

/* Avoid -0.0 with downward rounding.  */

/* The underflow exception needs to be signaled explicitly.  */

/* Top 12 bits of a double (sign and exponent bits).  */

/* Avoid spurious underflow for tiny x.  */

/* Note: 0 is common input.  */

/* Large x is special cased below.  */

/* exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)].  */

/* x = k/N + r, with int k and r in [-1/2N, 1/2N].  */

/* k.  */

/* k/N for int k.  */

/* 2^(k/N) ~= scale * (1 + tail).  */

/* This is only a valid scale when -1023*N < k < 1024*N.  */

/* exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1).  */

/* Evaluation is optimized assuming superscalar pipelined execution.  */

/* Without fma the worst case error is 0.5/N ulp larger.  */

/* Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp.  */

/* Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there
	   is no spurious underflow here even without fma.  */


=== system/lib/libc/musl/src/math/exp2f.c ===
SHA256: 1753e636d3b395160a03e9dd4a4ed4fba2abcd9ee12e4cf2d919f5a6bd7e2732
Primary Git blob: 0360482cae0a371d43a0b8f9faf5569eea87a18c
/*
 * Single-precision 2^x function.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/*
EXP2F_TABLE_BITS = 5
EXP2F_POLY_ORDER = 3

ULP error: 0.502 (nearest rounding.)
Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)
Wrong count: 168353 (all nearest rounding wrong results with fma.)
Non-nearest ULP error: 1 (rounded ULP error)
*/

/* |x| >= 128 or x is nan.  */

/* x = k/N + r with r in [-1/(2N), 1/(2N)] and int k.  */

/* k/N for int k.  */

/* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */


=== system/lib/libc/musl/src/math/exp2f_data.c ===
SHA256: 3da38c471cc5eb8dc1c2e283c6c00a36b1d353ba5c8ca1e82d95180948e26bd5
Primary Git blob: be324727f5f10704339f814ef69ae16213de0339
/*
 * Shared data between expf, exp2f and powf.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* tab[i] = uint(2^(i/N)) - (i << 52-BITS)
     used for computing 2^(k/N) for an int |k| < 150 N as
     double(tab[k%N] + (k << 52-BITS)) */


=== system/lib/libc/musl/src/math/exp2f_data.h ===
SHA256: fb52b690bef63df2e8996f2d2b3fd77f9ea08795863e73afdc882df04460e850
Primary Git blob: fe744f15beb216f60e6ad1f61e4fc131e331cacc
/*
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* Shared between expf, exp2f and powf.  */


=== system/lib/libc/musl/src/math/exp2l.c ===
SHA256: 0eeba2725b540b0d5dd84b732d4c496d8e8d9492cf863dbb5c83fe102771352c
Primary Git blob: 3565c1e67da8e4583562579b1456a7b8bff7edb3
/* origin: FreeBSD /usr/src/lib/msun/ld80/s_exp2l.c and /usr/src/lib/msun/ld128/s_exp2l.c */

/*-
 * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * exp2l(x): compute the base 2 exponential of x
 *
 * Accuracy: Peak error < 0.511 ulp.
 *
 * Method: (equally-spaced tables)
 *
 *   Reduce x:
 *     x = 2**k + y, for integer k and |y| <= 1/2.
 *     Thus we have exp2l(x) = 2**k * exp2(y).
 *
 *   Reduce y:
 *     y = i/TBLSIZE + z for integer i near y * TBLSIZE.
 *     Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z),
 *     with |z| <= 2**-(TBLBITS+1).
 *
 *   We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a
 *   degree-6 minimax polynomial with maximum error under 2**-69.
 *   The table entries each have 104 bits of accuracy, encoded as
 *   a pair of double precision values.
 */

/* Filter out exceptional cases. */

/* |x| >= 8192 or x is NaN */

/* overflow */

/* -inf or -nan */

/* underflow */

/*
	 * Reduce x, computing z, i0, and k. The low bits of x + redux
	 * contain the 16-bit integer part of the exponent (k) followed by
	 * TBLBITS fractional bits (i0). We use bit tricks to extract these
	 * as integers, then set z to the remainder.
	 *
	 * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8.
	 * Then the low-order word of x + redux is 0x000abc12,
	 * We split this into k = 0xabc and i0 = 0x12 (adjusted to
	 * index into the table), then we compute z = 0x0.003456p0.
	 */

/* Compute r = exp2l(y) = exp2lt[i0] * p(z). */

/* XXX This gives > 1 ulp errors outside of FE_TONEAREST mode */

/*
 * exp2l(x): compute the base 2 exponential of x
 *
 * Accuracy: Peak error < 0.502 ulp.
 *
 * Method: (accurate tables)
 *
 *   Reduce x:
 *     x = 2**k + y, for integer k and |y| <= 1/2.
 *     Thus we have exp2(x) = 2**k * exp2(y).
 *
 *   Reduce y:
 *     y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE.
 *     Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]),
 *     with |z - eps[i]| <= 2**-8 + 2**-98 for the table used.
 *
 *   We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via
 *   a degree-10 minimax polynomial with maximum error under 2**-120.
 *   The values in exp2t[] and eps[] are chosen such that
 *   exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such
 *   that exp2t[i] is accurate to 2**-122.
 *
 *   Note that the range of i is +-TBLSIZE/2, so we actually index the tables
 *   by i0 = i + TBLSIZE/2.
 *
 *   This method is due to Gal, with many details due to Gal and Bachelis:
 *
 *	Gal, S. and Bachelis, B.  An Accurate Elementary Mathematical Library
 *	for the IEEE Floating Point Standard.  TOMS 17(1), 26-46 (1991).
 */

/* Filter out exceptional cases. */

/* |x| >= 16384 or x is NaN */

/* overflow */

/* -inf or -nan */

/* underflow */

/*
	 * Reduce x, computing z, i0, and k. The low bits of x + redux
	 * contain the 16-bit integer part of the exponent (k) followed by
	 * TBLBITS fractional bits (i0). We use bit tricks to extract these
	 * as integers, then set z to the remainder.
	 *
	 * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8.
	 * Then the low-order word of x + redux is 0x000abc12,
	 * We split this into k = 0xabc and i0 = 0x12 (adjusted to
	 * index into the table), then we compute z = 0x0.003456p0.
	 */

/* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */


=== system/lib/libc/musl/src/math/exp_data.c ===
SHA256: c55dff64e369fe816cd8ce367064989bb119f85783599680d1a329031c660689
Primary Git blob: 21be0146a1674daf9750166c382be5c1591a4b4e
/*
 * Shared data between exp, exp2 and pow.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

// N/ln2

// -ln2/N

// Used for rounding when !TOINT_INTRINSICS

// exp polynomial coefficients.

// abs error: 1.555*2^-66

// ulp error: 0.509 (0.511 without fma)

// if |x| < ln2/256+eps

// abs error if |x| < ln2/256+0x1p-15: 1.09*2^-65

// abs error if |x| < ln2/128: 1.7145*2^-56

// exp2 polynomial coefficients.

// abs error: 1.2195*2^-65

// ulp error: 0.507 (0.511 without fma)

// if |x| < 1/256

// abs error if |x| < 1/128: 1.9941*2^-56

// 2^(k/N) ~= H[k]*(1 + T[k]) for int k in [0,N)

// tab[2*k] = asuint64(T[k])

// tab[2*k+1] = asuint64(H[k]) - (k << 52)/N


=== system/lib/libc/musl/src/math/exp_data.h ===
SHA256: df77fca837edd02b260dd09a2914202775909ae67a059218ae38cfab104e6d16
Primary Git blob: 3e24bac57a80f46c4a7b75aefe7215df810e85b6
/*
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* Last four coefficients.  */


=== system/lib/libc/musl/src/math/expf.c ===
SHA256: 225123b9b3a47a083c06f2580c6b73d5cadae5cec545f9e928f7041ff837b4b4
Primary Git blob: f9fbf8e727db635c0ea0b5685d374895b8bbffd2
/*
 * Single-precision e^x function.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/*
EXP2F_TABLE_BITS = 5
EXP2F_POLY_ORDER = 3

ULP error: 0.502 (nearest rounding.)
Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)
Wrong count: 170635 (all nearest rounding wrong results with fma.)
Non-nearest ULP error: 1 (rounded ULP error)
*/

/* |x| >= 88 or x is nan.  */

/* x > log(0x1p128) ~= 88.72 */

/* x < log(0x1p-150) ~= -103.97 */

/* x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k.  */

/* Round and convert z to int, the result is in [-150*N, 128*N] and
	   ideally ties-to-even rule is used, otherwise the magnitude of r
	   can be bigger which gives larger approximation error.  */

/* exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */


=== system/lib/libc/musl/src/math/expl.c ===
SHA256: 7218f10e56cd73c76f01a6924373dd1918730a0e793cf3c64670a34346173e68
Primary Git blob: 0a7f44f685ee3b708962dc9683698ffcd8074775
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_expl.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Exponential function, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, expl();
 *
 * y = expl( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns e (2.71828...) raised to the x power.
 *
 * Range reduction is accomplished by separating the argument
 * into an integer k and fraction f such that
 *
 *     x    k  f
 *    e  = 2  e.
 *
 * A Pade' form of degree 5/6 is used to approximate exp(f) - 1
 * in the basic range [-0.5 ln 2, 0.5 ln 2].
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      +-10000     50000       1.12e-19    2.81e-20
 *
 *
 * Error amplification in the exponential function can be
 * a serious matter.  The error propagation involves
 * exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ),
 * which shows that a 1 lsb error in representing X produces
 * a relative error of X times 1 lsb in the function.
 * While the routine gives an accurate result for arguments
 * that are exactly represented by a long double precision
 * computer number, the result contains amplified roundoff
 * error for large arguments not exactly represented.
 *
 *
 * ERROR MESSAGES:
 *
 *   message         condition      value returned
 * exp underflow    x < MINLOG         0.0
 * exp overflow     x > MAXLOG         MAXNUM
 *
 */

/* x > ln(2^16384 - 0.5) */

/* x < ln(2^-16446) */

/* Express e**x = e**f 2**k
	 *   = e**(f + k ln(2))
	 */

/* rational approximation of the fractional part:
	 * e**x =  1 + 2x P(x**2)/(Q(x**2) - x P(x**2))
	 */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/expm1.c ===
SHA256: c4764166cea03420f2dfc1840a6a7615934192d851b96d5d2dcc321cc1e39460
Primary Git blob: ac1e61e4f7f6a0d09651c814f7885cc6f25b163a
/* origin: FreeBSD /usr/src/lib/msun/src/s_expm1.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* expm1(x)
 * Returns exp(x)-1, the exponential of x minus 1.
 *
 * Method
 *   1. Argument reduction:
 *      Given x, find r and integer k such that
 *
 *               x = k*ln2 + r,  |r| <= 0.5*ln2 ~ 0.34658
 *
 *      Here a correction term c will be computed to compensate
 *      the error in r when rounded to a floating-point number.
 *
 *   2. Approximating expm1(r) by a special rational function on
 *      the interval [0,0.34658]:
 *      Since
 *          r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ...
 *      we define R1(r*r) by
 *          r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r)
 *      That is,
 *          R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)
 *                   = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))
 *                   = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...
 *      We use a special Remez algorithm on [0,0.347] to generate
 *      a polynomial of degree 5 in r*r to approximate R1. The
 *      maximum error of this polynomial approximation is bounded
 *      by 2**-61. In other words,
 *          R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5
 *      where   Q1  =  -1.6666666666666567384E-2,
 *              Q2  =   3.9682539681370365873E-4,
 *              Q3  =  -9.9206344733435987357E-6,
 *              Q4  =   2.5051361420808517002E-7,
 *              Q5  =  -6.2843505682382617102E-9;
 *              z   =  r*r,
 *      with error bounded by
 *          |                  5           |     -61
 *          | 1.0+Q1*z+...+Q5*z   -  R1(z) | <= 2
 *          |                              |
 *
 *      expm1(r) = exp(r)-1 is then computed by the following
 *      specific way which minimize the accumulation rounding error:
 *                             2     3
 *                            r     r    [ 3 - (R1 + R1*r/2)  ]
 *            expm1(r) = r + --- + --- * [--------------------]
 *                            2     2    [ 6 - r*(3 - R1*r/2) ]
 *
 *      To compensate the error in the argument reduction, we use
 *              expm1(r+c) = expm1(r) + c + expm1(r)*c
 *                         ~ expm1(r) + c + r*c
 *      Thus c+r*c will be added in as the correction terms for
 *      expm1(r+c). Now rearrange the term to avoid optimization
 *      screw up:
 *                      (      2                                    2 )
 *                      ({  ( r    [ R1 -  (3 - R1*r/2) ]  )  }    r  )
 *       expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- )
 *                      ({  ( 2    [ 6 - r*(3 - R1*r/2) ]  )  }    2  )
 *                      (                                             )
 *
 *                 = r - E
 *   3. Scale back to obtain expm1(x):
 *      From step 1, we have
 *         expm1(x) = either 2^k*[expm1(r)+1] - 1
 *                  = or     2^k*[expm1(r) + (1-2^-k)]
 *   4. Implementation notes:
 *      (A). To save one multiplication, we scale the coefficient Qi
 *           to Qi*2^i, and replace z by (x^2)/2.
 *      (B). To achieve maximum accuracy, we compute expm1(x) by
 *        (i)   if x < -56*ln2, return -1.0, (raise inexact if x!=inf)
 *        (ii)  if k=0, return r-E
 *        (iii) if k=-1, return 0.5*(r-E)-0.5
 *        (iv)  if k=1 if r < -0.25, return 2*((r+0.5)- E)
 *                     else          return  1.0+2.0*(r-E);
 *        (v)   if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1)
 *        (vi)  if k <= 20, return 2^k((1-2^-k)-(E-r)), else
 *        (vii) return 2^k(1-((E+2^-k)-r))
 *
 * Special cases:
 *      expm1(INF) is INF, expm1(NaN) is NaN;
 *      expm1(-INF) is -1, and
 *      for finite argument, only expm1(0)=0 is exact.
 *
 * Accuracy:
 *      according to an error analysis, the error is always less than
 *      1 ulp (unit in the last place).
 *
 * Misc. info.
 *      For IEEE double
 *          if x >  7.09782712893383973096e+02 then expm1(x) overflow
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

/* 0x40862E42, 0xFEFA39EF */

/* 0x3fe62e42, 0xfee00000 */

/* 0x3dea39ef, 0x35793c76 */

/* 0x3ff71547, 0x652b82fe */

/* Scaled Q's: Qn_here = 2**n * Qn_above, for R(2*z) where z = hxs = x*x/2: */

/* BFA11111 111110F4 */

/* 3F5A01A0 19FE5585 */

/* BF14CE19 9EAADBB7 */

/* 3ED0CFCA 86E65239 */

/* BE8AFDB7 6E09C32D */

/* filter out huge and non-finite argument */

/* if |x|>=56*ln2 */

/* argument reduction */

/* if  |x| > 0.5 ln2 */

/* and |x| < 1.5 ln2 */

/* t*ln2_hi is exact here */

/* |x| < 2**-54, return x */

/* x is now in primary range */

/* c is 0 */

/* exp(x) ~ 2^k (x_reduced - e + 1) */

/* 2^k */

/* suffice to return exp(x)-1 */

/* 2^-k */


=== system/lib/libc/musl/src/math/expm1f.c ===
SHA256: a7d4e8f8b41f04d4b977deb59e6bf96067371387062a5987fcc3b4464f54f5e9
Primary Git blob: 09a41afe7d2c00117672fe9c3c709e27d55001fa
/* origin: FreeBSD /usr/src/lib/msun/src/s_expm1f.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x3f317180 */

/* 0x3717f7d1 */

/* 0x3fb8aa3b */

/*
 * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]:
 * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04
 * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c):
 */

/* -0x888868.0p-28 */

/*  0xcf3010.0p-33 */

/* filter out huge and non-finite argument */

/* if |x|>=27*ln2 */

/* NaN */

/* x > log(FLT_MAX) */

/* argument reduction */

/* if  |x| > 0.5 ln2 */

/* and |x| < 1.5 ln2 */

/* t*ln2_hi is exact here */

/* when |x|<2**-25, return x */

/* x is now in primary range */

/* c is 0 */

/* exp(x) ~ 2^k (x_reduced - e + 1) */

/* 2^k */

/* suffice to return exp(x)-1 */

/* 2^-k */


=== system/lib/libc/musl/src/math/expm1l.c ===
SHA256: a8362abd18ef31f00a7dd74c8b618ef658a4e9c3919c456d03d65a12fe445c2f
Primary Git blob: d17150785282f9ce2e566de629b0061cd8848207
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_expm1l.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Exponential function, minus 1
 *      Long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, expm1l();
 *
 * y = expm1l( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns e (2.71828...) raised to the x power, minus 1.
 *
 * Range reduction is accomplished by separating the argument
 * into an integer k and fraction f such that
 *
 *     x    k  f
 *    e  = 2  e.
 *
 * An expansion x + .5 x^2 + x^3 R(x) approximates exp(f) - 1
 * in the basic range [-0.5 ln 2, 0.5 ln 2].
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE    -45,+maxarg   200,000     1.2e-19     2.5e-20
 */

/* exp(x) - 1 = x + 0.5 x^2 + x^3 P(x)/Q(x)
   -.5 ln 2  <  x  <  .5 ln 2
   Theoretical peak relative error = 3.4e-22  */

/* Q5 = 1.000000000000000000000000000000000000000E0 */

/* C1 + C2 = ln 2 */

/* ln 2^-65 */

/* ln 2^16384 */

/* overflow, unless x==inf */

/* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */

/* remainder times ln 2 */

/* Approximate exp(remainder ln 2).*/

/* exp(x) = exp(k ln 2) exp(remainder ln 2) = 2^k exp(remainder ln 2).
	 We have qx = exp(remainder ln 2) - 1, so
	 exp(x) - 1  =  2^k (qx + 1) - 1  =  2^k qx + 2^k - 1.  */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/fabs.c ===
SHA256: f6387612e1f879cac47fa71a808b584c76d78c23df4e44274ed9c7b1ddf24eff
Primary Git blob: 566a461ffdd37aaf67eec74b8eb90ec7df55bdd8
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/fabsf.c ===
SHA256: 0d49f81e5f9abff1d0a72d16bb0fc5f55cb950623627abac0402ee4c900a1734
Primary Git blob: 1ff074a720c752310dde76de6e15355b436acdb8
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/floor.c ===
SHA256: c72285ce3c43df30ccc737a1a91d65144f28c7777cae23f1b526806fb1b1188a
Primary Git blob: 179a9aca1de509bac984c83879d26d32e8efaeaf
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236

/* y = int(x) - x, where int(x) is an integer neighbor of x */

/* special case because of non-nearest rounding modes */


=== system/lib/libc/musl/src/math/floorf.c ===
SHA256: 86066c5fef654b3aa1eb742e11a92f9efcbd0f3dd7abdd9e3c2ac1e7002e6690
Primary Git blob: 4552d38bc57238a7b45fe558c2fccfa93e2026d9
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/floorl.c ===
SHA256: 2e8587117da3b71b111e899b9a9372926e1656d06a228b027d0cb733cd445c20
Primary Git blob: 16aaec48eea8e4e28e747122d6179d95e279981f
/* y = int(x) - x, where int(x) is an integer neighbor of x */

/* special case because of non-nearest rounding modes */


=== system/lib/libc/musl/src/math/fma.c ===
SHA256: 1e0c6bacd92cbbadb32d1f83defd52cd863fd766b7938efabafcef9f067d5860
Primary Git blob: 5336a2d5044675876d5c657d19976e6ae3bd4990
/* normalize so top 10bits and last bit are 0 */

/* z==0 */

/* mul: r = x*y */

/* either top 20 or 21 bits of rhi and last 2 bits of rlo are 0 */

/* align exponents */

/* shift bits z<<=kz, r>>=kr, so kz+kr == d, set e = e+kr (== ez-kz) */

/* add */

/* r += z */

/* r -= z */

/* set rhi to top 63bit of the result (last bit is sticky) */

/* note: d > 0 */

/* exact +-0 */

/* convert to double */

/* i is in [1<<62,(1<<63)-1] */

/* |r| is in [0x1p62,0x1p63] */

/* result is subnormal before rounding */

/* min normal after rounding, underflow depends
				   on arch behaviour which can be imitated by
				   a double to float conversion */

/* one bit is lost when scaled, add another top bit to
			   only round once at conversion if it is inexact */

/* remove top bit */

/* raise underflow portably, such that it
				   cannot be optimized away */

/* only round once when scaled */


=== system/lib/libc/musl/src/math/fmaf.c ===
SHA256: 8cef4678e7e82d5be0775e51ac11bbcb680f39005482470f5cfb3ed201cd3620
Primary Git blob: bb4f6f1daa6eb086f5f14c87e988cad2d8945b0b
/* origin: FreeBSD /usr/src/lib/msun/src/s_fmaf.c */

/*-
 * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * Fused multiply-add: Compute x * y + z with a single rounding error.
 *
 * A double has more than twice as much precision than a float, so
 * direct double-precision arithmetic suffices, except where double
 * rounding occurs.
 */

/* Common case: The double precision result is fine. */

/* not a halfway case */

/* NaN */

/* exact */

/* not round-to-nearest */

/*
		underflow may not be raised correctly, example:
		fmaf(0x1p-120f, 0x1p-120f, 0x1p-149f)
		*/

/* TODO: gcc and clang bug workaround */

/*
	 * If result is inexact, and exactly halfway between two float values,
	 * we need to adjust the low-order bit in the direction of the error.
	 */


=== system/lib/libc/musl/src/math/fmal.c ===
SHA256: b53603203db358624a037ddbe1ca4b7563bb31f3381686ed11621ccd8b247ac9
Primary Git blob: ac8ecbbb2a6e06ad3c25dcfa54ed9e9e41bc4c4b
/* origin: FreeBSD /usr/src/lib/msun/src/s_fmal.c */

/*-
 * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/*
 * A struct dd represents a floating-point number with twice the precision
 * of a long double.  We maintain the invariant that "hi" stores the high-order
 * bits of the result.
 */

/*
 * Compute a+b exactly, returning the exact result in a struct dd.  We assume
 * that both a and b are finite, but make no assumptions about their relative
 * magnitudes.
 */

/*
 * Compute a+b, with a small tweak:  The least significant bit of the
 * result is adjusted into a sticky bit summarizing all the bits that
 * were lost to rounding.  This adjustment negates the effects of double
 * rounding when the result is added to another number with a higher
 * exponent.  For an explanation of round and sticky bits, see any reference
 * on FPU design, e.g.,
 *
 *     J. Coonen.  An Implementation Guide to a Proposed Standard for
 *     Floating-Point Arithmetic.  Computer, vol. 13, no. 1, Jan 1980.
 */

/*
 * Compute ldexp(a+b, scale) with a single rounding error. It is assumed
 * that the result will be subnormal, and care is taken to ensure that
 * double rounding does not occur.
 */

/*
	 * If we are losing at least two bits of accuracy to denormalization,
	 * then the first lost bit becomes a round bit, and we adjust the
	 * lowest bit of sum.hi to make it a sticky bit summarizing all the
	 * bits in sum.lo. With the sticky bit adjusted, the hardware will
	 * break any ties in the correct direction.
	 *
	 * If we are losing only one bit to denormalization, however, we must
	 * break the ties manually.
	 */

/*
 * Compute a*b exactly, returning the exact result in a struct dd.  We assume
 * that both a and b are normalized, so no underflow or overflow will occur.
 * The current rounding mode must be round-to-nearest.
 */

/*
 * Fused multiply-add: Compute x * y + z with a single rounding error.
 *
 * We use scaling to avoid overflow/underflow, along with the
 * canonical precision-doubling technique adapted from:
 *
 *      Dekker, T.  A Floating-Point Technique for Extending the
 *      Available Precision.  Numer. Math. 18, 224-242 (1971).
 */

/*
	 * Handle special cases. The order of operations and the particular
	 * return values here are crucial in handling special cases involving
	 * infinities, NaNs, overflows, and signed zeroes correctly.
	 */

/*
	 * If x * y and z are many orders of magnitude apart, the scaling
	 * will overflow, so we handle these cases specially.  Rounding
	 * modes other than FE_TONEAREST are painful.
	 */

/* FE_TONEAREST */

/*
	 * Basic approach for round-to-nearest:
	 *
	 *     (xy.hi, xy.lo) = x * y           (exact)
	 *     (r.hi, r.lo)   = xy.hi + z       (exact)
	 *     adj = xy.lo + r.lo               (inexact; low bit is sticky)
	 *     result = r.hi + adj              (correctly rounded)
	 */

/*
		 * When the addends cancel to 0, ensure that the result has
		 * the correct sign.
		 */

/* XXX gcc CSE bug workaround */

/*
		 * There is no need to worry about double rounding in directed
		 * rounding modes.
		 * But underflow may not be raised correctly, example in downward rounding:
		 * fmal(0x1.0000000001p-16000L, 0x1.0000000001p-400L, -0x1p-16440L)
		 */


=== system/lib/libc/musl/src/math/fmax.c ===
SHA256: c05d0925886dcf156e36f91859c25d9990a25c32633b15e2a3dc695386416af7
Primary Git blob: 2018a78c6978a15a0e326f957f88251591145e0e
// XXX EMSCRIPTEN: use wasm builtins for code size

/* handle signed zeros, see C99 Annex F.9.9.2 */


=== system/lib/libc/musl/src/math/fmaxf.c ===
SHA256: 5465375657a294c7db3c2010db54d037afc464b06cca017e49dcbf8aef38393e
Primary Git blob: 8524cee49dce38c8ff5a649a347ce0f4fe65b612
// XXX EMSCRIPTEN: use wasm builtins for code size

/* handle signed zeroes, see C99 Annex F.9.9.2 */


=== system/lib/libc/musl/src/math/fmaxl.c ===
SHA256: 9c2d49e72f416c416827e3ac6cd68d95995add2cfb96c34c815f3f9dd9951d59
Primary Git blob: 4b03158e06292b28576615a2a1dd36bd6bf1d34a
/* handle signed zeros, see C99 Annex F.9.9.2 */


=== system/lib/libc/musl/src/math/fmin.c ===
SHA256: a3500c2e89748ebfa6b1dc2d901f2e4c49e87566590031c494e82d888e94312e
Primary Git blob: 2334d7b898a30888fdc581ce2f2be0b430c13978
// XXX EMSCRIPTEN: use wasm builtins for code size

/* handle signed zeros, see C99 Annex F.9.9.2 */


=== system/lib/libc/musl/src/math/fminf.c ===
SHA256: 07c3e7202556218656c39cb006f49235ef39c07ef749b4a5b0e656e5aebc1313
Primary Git blob: bfbaafcef80b9ca4e38ef6d03c74fd62b9ffc2b8
// XXX EMSCRIPTEN: use wasm builtins for code size

/* handle signed zeros, see C99 Annex F.9.9.2 */


=== system/lib/libc/musl/src/math/fminl.c ===
SHA256: 7c15f9d8948fba8392a065d90db350f89ff5e964903f4fc0c9bb425ffb8f4a6a
Primary Git blob: 69bc24a79bef742518735980c2ff5919589fbb46
/* handle signed zeros, see C99 Annex F.9.9.2 */


=== system/lib/libc/musl/src/math/fmod.c ===
SHA256: 33fb61093e04783081b9e8f8a8a303456b2f919c215cd0c378c1ed0acf41934c
Primary Git blob: 6849722bac50e477b9210f57f0271dcdabd8ae0c
/* in the followings uxi should be ux.i, but then gcc wrongly adds */

/* float load/store to inner loops ruining performance and code size */

/* normalize x and y */

/* x mod y */

/* scale result */


=== system/lib/libc/musl/src/math/fmodf.c ===
SHA256: eecc1cf499f143181880a33a95f1614be323aca704815a7b57d4969a7cacc2d4
Primary Git blob: ff58f93365b47a7083678fc4693db293afbb6f46
/* normalize x and y */

/* x mod y */

/* scale result up */


=== system/lib/libc/musl/src/math/fmodl.c ===
SHA256: 2e0331976ad4414bae10293befdb06a36b89cb8a7fcd66522cdb48c8485b97cb
Primary Git blob: 9f5b87393dcad9ffcd44876d7b76120563a3e85f
/* normalize x and y */

/* x mod y */

/* scale result */


=== system/lib/libc/musl/src/math/hypot.c ===
SHA256: a5532b3328310bb3ac9f7cd9074fd26c5fe7288c719c907c5c03a615442f9e7e
Primary Git blob: 6071bf1e284f376f417dbab5bc306964a7491f3f
/* arrange |x| >= |y| */

/* special cases */

/* note: hypot(inf,nan) == inf */

/* note: hypot(x,y) ~= x + y*y/x/2 with inexact for small y/x */

/* 64 difference is enough for ld80 double_t */

/* precise sqrt argument in nearest rounding mode without overflow */

/* xh*xh must not overflow and xl*xl must not underflow in sq */


=== system/lib/libc/musl/src/math/ilogb.c ===
SHA256: 3fd3907fe84685438e5eaf8eb124d3d4e8b2cd8c24b6939de36a34f86b2a7173
Primary Git blob: a52d78ef7dcecd1b4d7e790c79d047e16da96e06
/* subnormal x */


=== system/lib/libc/musl/src/math/ilogbf.c ===
SHA256: b23ee51bdce909bb90594b49a6370d98849755e3b98a06797001b813f2469d03
Primary Git blob: 18aef0ae043ddb46e7f6ee86fe0d5e3b32fda5e6
/* subnormal x */


=== system/lib/libc/musl/src/math/ilogbl.c ===
SHA256: ca3709cc1a99c8a73c1822d35513560b4cfdb1725dbd911a65768a06af52553f
Primary Git blob: 9931cac52ca6a390226962adceb77461d6f84e00
/* subnormal x */

/* subnormal x */


=== system/lib/libc/musl/src/math/j0.c ===
SHA256: 88fc190ff03d253791b9fab281caf82e5943e5d4251052c91cc29b14b39055bd
Primary Git blob: d722d942804524e65c08f0bf1cea8d5c8c738d77
/* origin: FreeBSD /usr/src/lib/msun/src/e_j0.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* j0(x), y0(x)
 * Bessel function of the first and second kinds of order zero.
 * Method -- j0(x):
 *      1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
 *      2. Reduce x to |x| since j0(x)=j0(-x),  and
 *         for x in (0,2)
 *              j0(x) = 1-z/4+ z^2*R0/S0,  where z = x*x;
 *         (precision:  |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
 *         for x in (2,inf)
 *              j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
 *         where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
 *         as follow:
 *              cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
 *                      = 1/sqrt(2) * (cos(x) + sin(x))
 *              sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
 *                      = 1/sqrt(2) * (sin(x) - cos(x))
 *         (To avoid cancellation, use
 *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
 *          to compute the worse one.)
 *
 *      3 Special cases
 *              j0(nan)= nan
 *              j0(0) = 1
 *              j0(inf) = 0
 *
 * Method -- y0(x):
 *      1. For x<2.
 *         Since
 *              y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
 *         therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
 *         We use the following function to approximate y0,
 *              y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
 *         where
 *              U(z) = u00 + u01*z + ... + u06*z^6
 *              V(z) = 1  + v01*z + ... + v04*z^4
 *         with absolute approximation error bounded by 2**-72.
 *         Note: For tiny x, U/V = u0 and j0(x)~1, hence
 *              y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
 *      2. For x>=2.
 *              y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
 *         where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
 *         by the method mentioned above.
 *      3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
 */

/* 0x3FE20DD7, 0x50429B6D */

/* 0x3FE45F30, 0x6DC9C883 */

/* common method when |x|>=2 */

/*
	 * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x-pi/4)-q0(x)*sin(x-pi/4))
	 * y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x-pi/4)+q0(x)*cos(x-pi/4))
	 *
	 * sin(x-pi/4) = (sin(x) - cos(x))/sqrt(2)
	 * cos(x-pi/4) = (sin(x) + cos(x))/sqrt(2)
	 * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
	 */

/* avoid overflow in 2*x, big ulp error when x>=0x1p1023 */

/* R0/S0 on [0, 2.00] */

/* 0x3F8FFFFF, 0xFFFFFFFD */

/* 0xBF28E6A5, 0xB61AC6E9 */

/* 0x3EBEB1D1, 0x0C503919 */

/* 0xBE33D5E7, 0x73D63FCE */

/* 0x3F8FFCE8, 0x82C8C2A4 */

/* 0x3F1EA6D2, 0xDD57DBF4 */

/* 0x3EA13B54, 0xCE84D5A9 */

/* 0x3E1408BC, 0xF4745D8F */

/* j0(+-inf)=0, j0(nan)=nan */

/* |x| >= 2 */

/* large ulp error near zeros: 2.4, 5.52, 8.6537,.. */

/* 1 - x*x/4 + x*x*R(x^2)/S(x^2) */

/* |x| >= 2**-13 */

/* up to 4ulp error close to 2 */

/* 1 - x*x/4 */

/* prevent underflow */

/* inexact should be raised when x!=0, this is not done correctly */

/* |x| >= 2**-127 */

/* 0xBFB2E4D6, 0x99CBD01F */

/* 0x3FC69D01, 0x9DE9E3FC */

/* 0xBF8C4CE8, 0xB16CFA97 */

/* 0x3F36C54D, 0x20B29B6B */

/* 0xBECFFEA7, 0x73D25CAD */

/* 0x3E550057, 0x3B4EABD4 */

/* 0xBDC5E43D, 0x693FB3C8 */

/* 0x3F8A1270, 0x91C9C71A */

/* 0x3F13ECBB, 0xF578C6C1 */

/* 0x3E91642D, 0x7FF202FD */

/* 0x3DFE5018, 0x3BD6D9EF */

/* y0(nan)=nan, y0(<0)=nan, y0(0)=-inf, y0(inf)=0 */

/* x >= 2 */

/* large ulp errors near zeros: 3.958, 7.086,.. */

/* U(x^2)/V(x^2) + (2/pi)*j0(x)*log(x) */

/* x >= 2**-27 */

/* large ulp error near the first zero, x ~= 0.89 */

/* The asymptotic expansions of pzero is
 *      1 - 9/128 s^2 + 11025/98304 s^4 - ...,  where s = 1/x.
 * For x >= 2, We approximate pzero by
 *      pzero(x) = 1 + (R/S)
 * where  R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
 *        S = 1 + pS0*s^2 + ... + pS4*s^10
 * and
 *      | pzero(x)-1-R/S | <= 2  ** ( -60.26)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000, 0x00000000 */

/* 0xBFB1FFFF, 0xFFFFFD32 */

/* 0xC02029D0, 0xB44FA779 */

/* 0xC0701102, 0x7B19E863 */

/* 0xC0A36A6E, 0xCD4DCAFC */

/* 0xC0B4850B, 0x36CC643D */

/* 0x405D2233, 0x07A96751 */

/* 0x40ADF37D, 0x50596938 */

/* 0x40E3D2BB, 0x6EB6B05F */

/* 0x40FC810F, 0x8F9FA9BD */

/* 0x40E74177, 0x4F2C49DC */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0xBDA918B1, 0x47E495CC */

/* 0xBFB1FFFF, 0xE69AFBC6 */

/* 0xC010A370, 0xF90C6BBF */

/* 0xC050EB2F, 0x5A7D1783 */

/* 0xC074B3B3, 0x6742CC63 */

/* 0xC075A6EF, 0x28A38BD7 */

/* 0x404E6081, 0x0C98C5DE */

/* 0x40906D02, 0x5C7E2864 */

/* 0x40B75AF8, 0x8FBE1D60 */

/* 0x40C2CCB8, 0xFA76FA38 */

/* 0x40A2CC1D, 0xC70BE864 */

/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */

/* 0xBE25E103, 0x6FE1AA86 */

/* 0xBFB1FFF6, 0xF7C0E24B */

/* 0xC00345B2, 0xAEA48074 */

/* 0xC035F74A, 0x4CB94E14 */

/* 0xC04D0A22, 0x420A1A45 */

/* 0xC03F72AC, 0xA892D80F */

/* 0x4041ED92, 0x84077DD3 */

/* 0x40769839, 0x464A7C0E */

/* 0x4092A66E, 0x6D1061D6 */

/* 0x40919FFC, 0xB8C39B7E */

/* 0x4065B296, 0xFC379081 */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0xBE77D316, 0xE927026D */

/* 0xBFB1FF62, 0x495E1E42 */

/* 0xBFF73639, 0x8A24A843 */

/* 0xC01E8AF3, 0xEDAFA7F3 */

/* 0xC02662E6, 0xC5246303 */

/* 0xC009DE81, 0xAF8FE70F */

/* 0x40363865, 0x908B5959 */

/* 0x4061069E, 0x0EE8878F */

/* 0x4070E786, 0x42EA079B */

/* 0x40633C03, 0x3AB6FAFF */

/* 0x402D50B3, 0x44391809 */

/*ix >= 0x40000000*/

/* For x >= 8, the asymptotic expansions of qzero is
 *      -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
 * We approximate pzero by
 *      qzero(x) = s*(-1.25 + (R/S))
 * where  R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
 *        S = 1 + qS0*s^2 + ... + qS5*s^12
 * and
 *      | qzero(x)/s +1.25-R/S | <= 2  ** ( -61.22)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000, 0x00000000 */

/* 0x3FB2BFFF, 0xFFFFFE2C */

/* 0x40278952, 0x5BB334D6 */

/* 0x40816D63, 0x15301825 */

/* 0x40C14D99, 0x3E18F46D */

/* 0x40E212D4, 0x0E901566 */

/* 0x406478D5, 0x365B39BC */

/* 0x40BFA258, 0x4E6B0563 */

/* 0x41016652, 0x54D38C3F */

/* 0x412883DA, 0x83A52B43 */

/* 0x4129A66B, 0x28DE0B3D */

/* 0xC114FD6D, 0x2C9530C5 */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0x3DB43D8F, 0x29CC8CD9 */

/* 0x3FB2BFFF, 0xD172B04C */

/* 0x401757B0, 0xB9953DD3 */

/* 0x4060E392, 0x0A8788E9 */

/* 0x40900CF9, 0x9DC8C481 */

/* 0x409F17E9, 0x53C6E3A6 */

/* 0x4054B1B3, 0xFB5E1543 */

/* 0x40A03BA0, 0xDA21C0CE */

/* 0x40D267D2, 0x7B591E6D */

/* 0x40EBB5E3, 0x97E02372 */

/* 0x40E19118, 0x1F7A54A0 */

/* 0xC0B4EA57, 0xBEDBC609 */

/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */

/* 0x3E32CD03, 0x6ADECB82 */

/* 0x3FB2BFEE, 0x0E8D0842 */

/* 0x400AC0FC, 0x61149CF5 */

/* 0x40454F98, 0x962DAEDD */

/* 0x406559DB, 0xE25EFD1F */

/* 0x4064D77C, 0x81FA21E0 */

/* 0x40486122, 0xBFE343A6 */

/* 0x40862D83, 0x86544EB3 */

/* 0x40ACF04B, 0xE44DFC63 */

/* 0x40B93C6C, 0xD7C76A28 */

/* 0x40A3A8AA, 0xD94FB1C0 */

/* 0xC062A7EB, 0x201CF40F */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0x3E84313B, 0x54F76BDB */

/* 0x3FB2BEC5, 0x3E883E34 */

/* 0x3FFFF897, 0xE727779C */

/* 0x402CFDBF, 0xAAF96FE5 */

/* 0x403FAA8E, 0x29FBDC4A */

/* 0x403040B1, 0x71814BB4 */

/* 0x403E5D96, 0xF7C07AED */

/* 0x4070D591, 0xE4D14B40 */

/* 0x408A6645, 0x22B3BF22 */

/* 0x408B977C, 0x9C5CC214 */

/* 0x406A9553, 0x0E001365 */

/* 0xC0153E6A, 0xF8B32931 */

/*ix >= 0x40000000*/


=== system/lib/libc/musl/src/math/j0f.c ===
SHA256: d0721c1c30f12badb67820e33299a2db0d9cec0209f7993fddee2a40d8d296a4
Primary Git blob: fab554a3119331e37f3d6cdd6826839e7cf2f1c6
/* origin: FreeBSD /usr/src/lib/msun/src/e_j0f.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x3f106ebb */

/* 0x3f22f983 */

/*
	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
	 */

/* R0/S0 on [0, 2.00] */

/* 0x3c800000 */

/* 0xb947352e */

/* 0x35f58e88 */

/* 0xb19eaf3c */

/* 0x3c7fe744 */

/* 0x38f53697 */

/* 0x3509daa6 */

/* 0x30a045e8 */

/* |x| >= 2 */

/* large ulp error near zeros */

/* |x| >= 2**-11 */

/* up to 4ulp error near 2 */

/* |x| >= 2**-60 */

/* 0xbd9726b5 */

/* 0x3e34e80d */

/* 0xbc626746 */

/* 0x39b62a69 */

/* 0xb67ff53c */

/* 0x32a802ba */

/* 0xae2f21eb */

/* 0x3c509385 */

/* 0x389f65e0 */

/* 0x348b216c */

/* 0x2ff280c2 */

/* |x| >= 2.0 */

/* large ulp error near zeros */

/* x >= 2**-13 */

/* large ulp error at x ~= 0.89 */

/* The asymptotic expansions of pzero is
 *      1 - 9/128 s^2 + 11025/98304 s^4 - ...,  where s = 1/x.
 * For x >= 2, We approximate pzero by
 *      pzero(x) = 1 + (R/S)
 * where  R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
 *        S = 1 + pS0*s^2 + ... + pS4*s^10
 * and
 *      | pzero(x)-1-R/S | <= 2  ** ( -60.26)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000 */

/* 0xbd900000 */

/* 0xc1014e86 */

/* 0xc3808814 */

/* 0xc51b5376 */

/* 0xc5a4285a */

/* 0x42e91198 */

/* 0x456f9beb */

/* 0x471e95db */

/* 0x47e4087c */

/* 0x473a0bba */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0xad48c58a */

/* 0xbd8fffff */

/* 0xc0851b88 */

/* 0xc287597b */

/* 0xc3a59d9b */

/* 0xc3ad3779 */

/* 0x42730408 */

/* 0x44836813 */

/* 0x45bad7c4 */

/* 0x461665c8 */

/* 0x451660ee */

/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */

/* 0xb12f081b */

/* 0xbd8fffb8 */

/* 0xc01a2d95 */

/* 0xc1afba52 */

/* 0xc2685112 */

/* 0xc1fb9565 */

/* 0x420f6c94 */

/* 0x43b4c1ca */

/* 0x44953373 */

/* 0x448cffe6 */

/* 0x432d94b8 */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0xb3be98b7 */

/* 0xbd8ffb12 */

/* 0xbfb9b1cc */

/* 0xc0f4579f */

/* 0xc1331736 */

/* 0xc04ef40d */

/* 0x41b1c32d */

/* 0x430834f0 */

/* 0x43873c32 */

/* 0x4319e01a */

/* 0x416a859a */

/*ix >= 0x40000000*/

/* For x >= 8, the asymptotic expansions of qzero is
 *      -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
 * We approximate pzero by
 *      qzero(x) = s*(-1.25 + (R/S))
 * where  R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
 *        S = 1 + qS0*s^2 + ... + qS5*s^12
 * and
 *      | qzero(x)/s +1.25-R/S | <= 2  ** ( -61.22)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000 */

/* 0x3d960000 */

/* 0x413c4a93 */

/* 0x440b6b19 */

/* 0x460a6cca */

/* 0x471096a0 */

/* 0x4323c6aa */

/* 0x45fd12c2 */

/* 0x480b3293 */

/* 0x49441ed4 */

/* 0x494d3359 */

/* 0xc8a7eb69 */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0x2da1ec79 */

/* 0x3d95ffff */

/* 0x40babd86 */

/* 0x43071c90 */

/* 0x448067cd */

/* 0x44f8bf4b */

/* 0x42a58da0 */

/* 0x4501dd07 */

/* 0x46933e94 */

/* 0x475daf1d */

/* 0x470c88c1 */

/* 0xc5a752be */

/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */

/* 0x3196681b */

/* 0x3d95ff70 */

/* 0x405607e3 */

/* 0x422a7cc5 */

/* 0x432acedf */

/* 0x4326bbe4 */

/* 0x42430916 */

/* 0x44316c1c */

/* 0x4567825f */

/* 0x45c9e367 */

/* 0x451d4557 */

/* 0xc3153f59 */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0x342189db */

/* 0x3d95f62a */

/* 0x3fffc4bf */

/* 0x4167edfd */

/* 0x41fd5471 */

/* 0x4182058c */

/* 0x41f2ecb8 */

/* 0x4386ac8f */

/* 0x44533229 */

/* 0x445cbbe5 */

/* 0x4354aa98 */

/* 0xc0a9f358 */

/*ix >= 0x40000000*/


=== system/lib/libc/musl/src/math/j1.c ===
SHA256: 73ec22fae7f2e3fccd2cc6ea777b296d0022a7c1d137035f1ef45cbf0c75ed4e
Primary Git blob: df724d172ea0064ea919d5eeee4627243f7df1d5
/* origin: FreeBSD /usr/src/lib/msun/src/e_j1.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* j1(x), y1(x)
 * Bessel function of the first and second kinds of order zero.
 * Method -- j1(x):
 *      1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
 *      2. Reduce x to |x| since j1(x)=-j1(-x),  and
 *         for x in (0,2)
 *              j1(x) = x/2 + x*z*R0/S0,  where z = x*x;
 *         (precision:  |j1/x - 1/2 - R0/S0 |<2**-61.51 )
 *         for x in (2,inf)
 *              j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
 *              y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
 *         where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
 *         as follow:
 *              cos(x1) =  cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
 *                      =  1/sqrt(2) * (sin(x) - cos(x))
 *              sin(x1) =  sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
 *                      = -1/sqrt(2) * (sin(x) + cos(x))
 *         (To avoid cancellation, use
 *              sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
 *          to compute the worse one.)
 *
 *      3 Special cases
 *              j1(nan)= nan
 *              j1(0) = 0
 *              j1(inf) = 0
 *
 * Method -- y1(x):
 *      1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
 *      2. For x<2.
 *         Since
 *              y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
 *         therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
 *         We use the following function to approximate y1,
 *              y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
 *         where for x in [0,2] (abs err less than 2**-65.89)
 *              U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4
 *              V(z) = 1  + v0[0]*z + ... + v0[4]*z^5
 *         Note: For tiny x, 1/x dominate y1 and hence
 *              y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
 *      3. For x>=2.
 *              y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
 *         where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
 *         by method mentioned above.
 */

/* 0x3FE20DD7, 0x50429B6D */

/* 0x3FE45F30, 0x6DC9C883 */

/*
	 * j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x-3pi/4)-q1(x)*sin(x-3pi/4))
	 * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x-3pi/4)+q1(x)*cos(x-3pi/4))
	 *
	 * sin(x-3pi/4) = -(sin(x) + cos(x))/sqrt(2)
	 * cos(x-3pi/4) = (sin(x) - cos(x))/sqrt(2)
	 * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
	 */

/* avoid overflow in 2*x */

/* R0/S0 on [0,2] */

/* 0xBFB00000, 0x00000000 */

/* 0x3F570D9F, 0x98472C61 */

/* 0xBEF0C5C6, 0xBA169668 */

/* 0x3E6AAAFA, 0x46CA0BD9 */

/* 0x3F939D0B, 0x12637E53 */

/* 0x3F285F56, 0xB9CDF664 */

/* 0x3EB3BFF8, 0x333F8498 */

/* 0x3E35AC88, 0xC97DFF2C */

/* 0x3DAB2ACF, 0xCFB97ED8 */

/* |x| >= 2 */

/* |x| >= 2**-127 */

/* avoid underflow, raise inexact if x!=0 */

/* 0xBFC91866, 0x143CBC8A */

/* 0x3FA9D3C7, 0x76292CD1 */

/* 0xBF5F55E5, 0x4844F50F */

/* 0x3EF8AB03, 0x8FA6B88E */

/* 0xBE78AC00, 0x569105B8 */

/* 0x3F94650D, 0x3F4DA9F0 */

/* 0x3F2A8C89, 0x6C257764 */

/* 0x3EB6C05A, 0x894E8CA6 */

/* 0x3E3ABF1D, 0x5BA69A86 */

/* 0x3DB25039, 0xDACA772A */

/* y1(nan)=nan, y1(<0)=nan, y1(0)=-inf, y1(inf)=0 */

/* x >= 2 */

/* x < 2**-54 */

/* For x >= 8, the asymptotic expansions of pone is
 *      1 + 15/128 s^2 - 4725/2^15 s^4 - ...,   where s = 1/x.
 * We approximate pone by
 *      pone(x) = 1 + (R/S)
 * where  R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
 *        S = 1 + ps0*s^2 + ... + ps4*s^10
 * and
 *      | pone(x)-1-R/S | <= 2  ** ( -60.06)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000, 0x00000000 */

/* 0x3FBDFFFF, 0xFFFFFCCE */

/* 0x402A7A9D, 0x357F7FCE */

/* 0x4079C0D4, 0x652EA590 */

/* 0x40AE457D, 0xA3A532CC */

/* 0x40BEEA7A, 0xC32782DD */

/* 0x405C8D45, 0x8E656CAC */

/* 0x40AC85DC, 0x964D274F */

/* 0x40E20B86, 0x97C5BB7F */

/* 0x40F7D42C, 0xB28F17BB */

/* 0x40DE1511, 0x697A0B2D */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0x3DAD0667, 0xDAE1CA7D */

/* 0x3FBDFFFF, 0xE2C10043 */

/* 0x401B3604, 0x6E6315E3 */

/* 0x405B13B9, 0x452602ED */

/* 0x40802D16, 0xD052D649 */

/* 0x408085B8, 0xBB7E0CB7 */

/* 0x404DA3EA, 0xA8AF633D */

/* 0x408EFB36, 0x1B066701 */

/* 0x40B4E944, 0x5706B6FB */

/* 0x40BEA4B0, 0xB8A5BB15 */

/* 0x40978030, 0x036F5E51 */

/* 0x3E29FC21, 0xA7AD9EDD */

/* 0x3FBDFFF5, 0x5B21D17B */

/* 0x400F76BC, 0xE85EAD8A */

/* 0x40418F48, 0x9DA6D129 */

/* 0x4056C385, 0x4D2C1837 */

/* 0x4048478F, 0x8EA83EE5 */

/* 0x40416549, 0xA134069C */

/* 0x40750C33, 0x07F1A75F */

/* 0x40905B7C, 0x5037D523 */

/* 0x408BD67D, 0xA32E31E9 */

/* 0x4059F26D, 0x7C2EED53 */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0x3E7CE9D4, 0xF65544F4 */

/* 0x3FBDFF42, 0xBE760D83 */

/* 0x4002F2B7, 0xF98FAEC0 */

/* 0x40287C37, 0x7F71A964 */

/* 0x4031B1A8, 0x177F8EE2 */

/* 0x40144B49, 0xA574C1FE */

/* 0x40356FBD, 0x8AD5ECDC */

/* 0x405F5293, 0x14F92CD5 */

/* 0x406D08D8, 0xD5A2DBD9 */

/* 0x405D6B7A, 0xDA1884A9 */

/* 0x4020BAB1, 0xF44E5192 */

/*ix >= 0x40000000*/

/* For x >= 8, the asymptotic expansions of qone is
 *      3/8 s - 105/1024 s^3 - ..., where s = 1/x.
 * We approximate pone by
 *      qone(x) = s*(0.375 + (R/S))
 * where  R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
 *        S = 1 + qs1*s^2 + ... + qs6*s^12
 * and
 *      | qone(x)/s -0.375-R/S | <= 2  ** ( -61.13)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000, 0x00000000 */

/* 0xBFBA3FFF, 0xFFFFFDF3 */

/* 0xC0304591, 0xA26779F7 */

/* 0xC087BCD0, 0x53E4B576 */

/* 0xC0C724E7, 0x40F87415 */

/* 0xC0E7A6D0, 0x65D09C6A */

/* 0x40642CA6, 0xDE5BCDE5 */

/* 0x40BE9162, 0xD0D88419 */

/* 0x4100579A, 0xB0B75E98 */

/* 0x4125F653, 0x72869C19 */

/* 0x412457D2, 0x7719AD5C */

/* 0xC111F969, 0x0EA5AA18 */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0xBDB6FA43, 0x1AA1A098 */

/* 0xBFBA3FFF, 0xCB597FEF */

/* 0xC0201CE6, 0xCA03AD4B */

/* 0xC066F56D, 0x6CA7B9B0 */

/* 0xC09574C6, 0x6931734F */

/* 0xC0A468E3, 0x88FDA79D */

/* 0x405451B2, 0xFF5A11B2 */

/* 0x409F1F31, 0xE77BF839 */

/* 0x40D10F1F, 0x0D64CE29 */

/* 0x40E8576D, 0xAABAD197 */

/* 0x40DB4B04, 0xCF7C364B */

/* 0xC0B26F2E, 0xFCFFA004 */

/* 0xBE35CFA9, 0xD38FC84F */

/* 0xBFBA3FEB, 0x51AEED54 */

/* 0xC01270C2, 0x3302D9FF */

/* 0xC04CEC71, 0xC25D16DA */

/* 0xC06C87D3, 0x4718D55F */

/* 0xC06B66B9, 0x5F5C1BF6 */

/* 0x4047D523, 0xCCD367E4 */

/* 0x40850EEB, 0xC031EE3E */

/* 0x40AA684E, 0x448E7C9A */

/* 0x40B5ABBA, 0xA61D54A6 */

/* 0x409DBC7A, 0x0DD4DF4B */

/* 0xC060E670, 0x290A311F */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0xBE87F126, 0x44C626D2 */

/* 0xBFBA3E8E, 0x9148B010 */

/* 0xC0060484, 0x69BB4EDA */

/* 0xC033A9E2, 0xC168907F */

/* 0xC04529A3, 0xDE104AAA */

/* 0xC0355F36, 0x39CF6E52 */

/* 0x403D888A, 0x78AE64FF */

/* 0x406F9F68, 0xDB821CBA */

/* 0x4087AC05, 0xCE49A0F7 */

/* 0x40871B25, 0x48D4C029 */

/* 0x40637E5E, 0x3C3ED8D4 */

/* 0xC013D686, 0xE71BE86B */

/*ix >= 0x40000000*/


=== system/lib/libc/musl/src/math/j1f.c ===
SHA256: 1b16747ce913d4e65dec522710265bd004f923a7f33b5e88d7e4057b9c7b8d79
Primary Git blob: 3434c53dcc2d8c535fbbfd38cc0b8308acdec571
/* origin: FreeBSD /usr/src/lib/msun/src/e_j1f.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x3f106ebb */

/* 0x3f22f983 */

/* R0/S0 on [0,2] */

/* 0xbd800000 */

/* 0x3ab86cfd */

/* 0xb7862e36 */

/* 0x335557d2 */

/* 0x3c9ce859 */

/* 0x3942fab6 */

/* 0x359dffc2 */

/* 0x31ad6446 */

/* 0x2d59567e */

/* |x| >= 2 */

/* |x| >= 2**-13 */

/* 0xbe48c331 */

/* 0x3d4e9e3c */

/* 0xbafaaf2a */

/* 0x37c5581c */

/* 0xb3c56003 */

/* 0x3ca3286a */

/* 0x3954644b */

/* 0x35b602d4 */

/* 0x31d5f8eb */

/* 0x2d9281cf */

/* |x| >= 2.0 */

/* x < 2**-25 */

/* For x >= 8, the asymptotic expansions of pone is
 *      1 + 15/128 s^2 - 4725/2^15 s^4 - ...,   where s = 1/x.
 * We approximate pone by
 *      pone(x) = 1 + (R/S)
 * where  R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
 *        S = 1 + ps0*s^2 + ... + ps4*s^10
 * and
 *      | pone(x)-1-R/S | <= 2  ** ( -60.06)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000 */

/* 0x3df00000 */

/* 0x4153d4ea */

/* 0x43ce06a3 */

/* 0x45722bed */

/* 0x45f753d6 */

/* 0x42e46a2c */

/* 0x45642ee5 */

/* 0x47105c35 */

/* 0x47bea166 */

/* 0x46f0a88b */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0x2d68333f */

/* 0x3defffff */

/* 0x40d9b023 */

/* 0x42d89dca */

/* 0x440168b7 */

/* 0x44042dc6 */

/* 0x426d1f55 */

/* 0x4477d9b1 */

/* 0x45a74a23 */

/* 0x45f52586 */

/* 0x44bc0180 */

/* 0x314fe10d */

/* 0x3defffab */

/* 0x407bb5e7 */

/* 0x420c7a45 */

/* 0x42b61c2a */

/* 0x42423c7c */

/* 0x420b2a4d */

/* 0x43a86198 */

/* 0x4482dbe3 */

/* 0x445eb3ed */

/* 0x42cf936c */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0x33e74ea8 */

/* 0x3deffa16 */

/* 0x401795c0 */

/* 0x4143e1bc */

/* 0x418d8d41 */

/* 0x40a25a4d */

/* 0x41ab7dec */

/* 0x42fa9499 */

/* 0x436846c7 */

/* 0x42eb5bd7 */

/* 0x4105d590 */

/*ix >= 0x40000000*/

/* For x >= 8, the asymptotic expansions of qone is
 *      3/8 s - 105/1024 s^3 - ..., where s = 1/x.
 * We approximate pone by
 *      qone(x) = s*(0.375 + (R/S))
 * where  R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
 *        S = 1 + qs1*s^2 + ... + qs6*s^12
 * and
 *      | qone(x)/s -0.375-R/S | <= 2  ** ( -61.13)
 */

/* for x in [inf, 8]=1/[0,0.125] */

/* 0x00000000 */

/* 0xbdd20000 */

/* 0xc1822c8d */

/* 0xc43de683 */

/* 0xc639273a */

/* 0xc73d3683 */

/* 0x43216537 */

/* 0x45f48b17 */

/* 0x4802bcd6 */

/* 0x492fb29c */

/* 0x4922be94 */

/* 0xc88fcb48 */

/* for x in [8,4.5454]=1/[0.125,0.22001] */

/* 0xadb7d219 */

/* 0xbdd1fffe */

/* 0xc100e736 */

/* 0xc337ab6b */

/* 0xc4aba633 */

/* 0xc523471c */

/* 0x42a28d98 */

/* 0x44f8f98f */

/* 0x468878f8 */

/* 0x4742bb6d */

/* 0x46da5826 */

/* 0xc5937978 */

/* 0xb1ae7d4f */

/* 0xbdd1ff5b */

/* 0xc0938612 */

/* 0xc267638e */

/* 0xc3643e9a */

/* 0xc35b35cb */

/* 0x423ea91e */

/* 0x4428775e */

/* 0x45534272 */

/* 0x45ad5dd5 */

/* 0x44ede3d0 */

/* 0xc3073381 */

/* for x in [2.8570,2]=1/[0.3499,0.5] */

/* 0xb43f8932 */

/* 0xbdd1f475 */

/* 0xc0302423 */

/* 0xc19d4f16 */

/* 0xc2294d1f */

/* 0xc1aaf9b2 */

/* 0x41ec4454 */

/* 0x437cfb47 */

/* 0x443d602e */

/* 0x4438d92a */

/* 0x431bf2f2 */

/* 0xc09eb437 */

/*ix >= 0x40000000*/


=== system/lib/libc/musl/src/math/jn.c ===
SHA256: cd602fc99cea2f33d8b39462f9f0523c8bc3da646fa349de87e206eb3bb2aded
Primary Git blob: 4878a54fedaebf474d1c3ee5c3993ea28e22998a
/* origin: FreeBSD /usr/src/lib/msun/src/e_jn.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * jn(n, x), yn(n, x)
 * floating point Bessel's function of the 1st and 2nd kind
 * of order n
 *
 * Special cases:
 *      y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
 *      y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
 * Note 2. About jn(n,x), yn(n,x)
 *      For n=0, j0(x) is called,
 *      for n=1, j1(x) is called,
 *      for n<=x, forward recursion is used starting
 *      from values of j0(x) and j1(x).
 *      for n>x, a continued fraction approximation to
 *      j(n,x)/j(n-1,x) is evaluated and then backward
 *      recursion is used starting from a supposed value
 *      for j(n,x). The resulting value of j(0,x) is
 *      compared with the actual value to correct the
 *      supposed value of j(n,x).
 *
 *      yn(n,x) is similar in all respects, except
 *      that forward recursion is used for all
 *      values of n>1.
 */

/* 0x3FE20DD7, 0x50429B6D */

/* nan */

/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
	 * Thus, J(-n,x) = J(n,-x)
	 */

/* nm1 = |n|-1 is used instead of |n| to handle n==INT_MIN */

/* even n: 0, odd n: signbit(x) */

/* if x is 0 or inf */

/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */

/* x > 2**302 */

/* (x >> n**2)
			 *      Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
			 *      Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
			 *      Let s=sin(x), c=cos(x),
			 *          xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
			 *
			 *             n    sin(xn)*sqt2    cos(xn)*sqt2
			 *          ----------------------------------
			 *             0     s-c             c+s
			 *             1    -s-c            -c+s
			 *             2    -s+c            -c-s
			 *             3     s+c             c-s
			 */

/* avoid underflow */

/* x < 2**-29 */

/* x is tiny, return the first Taylor expansion of J(n,x)
			 * J(n,x) = 1/n!*(x/2)^n  - ...
			 */

/* underflow */

/* a = n! */

/* b = (x/2)^n */

/* use backward recurrence */

/*                      x      x^2      x^2
			 *  J(n,x)/J(n-1,x) =  ----   ------   ------   .....
			 *                      2n  - 2(n+1) - 2(n+2)
			 *
			 *                      1      1        1
			 *  (for large x)   =  ----  ------   ------   .....
			 *                      2n   2(n+1)   2(n+2)
			 *                      -- - ------ - ------ -
			 *                       x     x         x
			 *
			 * Let w = 2n/x and h=2/x, then the above quotient
			 * is equal to the continued fraction:
			 *                  1
			 *      = -----------------------
			 *                     1
			 *         w - -----------------
			 *                        1
			 *              w+h - ---------
			 *                     w+2h - ...
			 *
			 * To determine how many terms needed, let
			 * Q(0) = w, Q(1) = w(w+h) - 1,
			 * Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
			 * When Q(k) > 1e4      good for single
			 * When Q(k) > 1e9      good for double
			 * When Q(k) > 1e17     good for quadruple
			 */

/* determine k */

/*  estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
			 *  Hence, if n*(log(2n/x)) > ...
			 *  single 8.8722839355e+01
			 *  double 7.09782712893383973096e+02
			 *  long double 1.1356523406294143949491931077970765006170e+04
			 *  then recurrent value may overflow and the result is
			 *  likely underflow to zero
			 */

/* scale b to avoid spurious overflow */

/* nan */

/* x < 0 */

/* x > 2**302 */

/* (x >> n**2)
		 *      Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
		 *      Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
		 *      Let s=sin(x), c=cos(x),
		 *          xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
		 *
		 *             n    sin(xn)*sqt2    cos(xn)*sqt2
		 *          ----------------------------------
		 *             0     s-c             c+s
		 *             1    -s-c            -c+s
		 *             2    -s+c            -c-s
		 *             3     s+c             c-s
		 */

/* quit if b is -inf */


=== system/lib/libc/musl/src/math/jnf.c ===
SHA256: cab6c734e9a718a3e7c41b22e0e69893453befa805f2ebdafca3264d81dbcf71
Primary Git blob: f63c062f32caf74b724f11e0ac97ece8da4d75b9
/* origin: FreeBSD /usr/src/lib/msun/src/e_jnf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* nan */

/* J(-n,x) = J(n,-x), use |n|-1 to avoid overflow in -n */

/* even n: 0, odd n: signbit(x) */

/* if x is 0 or inf */

/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */

/* x < 2**-20 */

/* x is tiny, return the first Taylor expansion of J(n,x)
			 * J(n,x) = 1/n!*(x/2)^n  - ...
			 */

/* underflow */

/* a = n! */

/* b = (x/2)^n */

/* use backward recurrence */

/*                      x      x^2      x^2
			 *  J(n,x)/J(n-1,x) =  ----   ------   ------   .....
			 *                      2n  - 2(n+1) - 2(n+2)
			 *
			 *                      1      1        1
			 *  (for large x)   =  ----  ------   ------   .....
			 *                      2n   2(n+1)   2(n+2)
			 *                      -- - ------ - ------ -
			 *                       x     x         x
			 *
			 * Let w = 2n/x and h=2/x, then the above quotient
			 * is equal to the continued fraction:
			 *                  1
			 *      = -----------------------
			 *                     1
			 *         w - -----------------
			 *                        1
			 *              w+h - ---------
			 *                     w+2h - ...
			 *
			 * To determine how many terms needed, let
			 * Q(0) = w, Q(1) = w(w+h) - 1,
			 * Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
			 * When Q(k) > 1e4      good for single
			 * When Q(k) > 1e9      good for double
			 * When Q(k) > 1e17     good for quadruple
			 */

/* determine k */

/*  estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
			 *  Hence, if n*(log(2n/x)) > ...
			 *  single 8.8722839355e+01
			 *  double 7.09782712893383973096e+02
			 *  long double 1.1356523406294143949491931077970765006170e+04
			 *  then recurrent value may overflow and the result is
			 *  likely underflow to zero
			 */

/* scale b to avoid spurious overflow */

/* nan */

/* x < 0 */

/* quit if b is -inf */


=== system/lib/libc/musl/src/math/lgamma_r.c ===
SHA256: df81910c12c2ba5e82295cea6bfc6f3863e367cc6043d1bf91be1fb9597b2811
Primary Git blob: f9984cd0c66031dd0c37c894daa0ee9be870b610
/* origin: FreeBSD /usr/src/lib/msun/src/e_lgamma_r.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 *
 */

/* lgamma_r(x, signgamp)
 * Reentrant version of the logarithm of the Gamma function
 * with user provide pointer for the sign of Gamma(x).
 *
 * Method:
 *   1. Argument Reduction for 0 < x <= 8
 *      Since gamma(1+s)=s*gamma(s), for x in [0,8], we may
 *      reduce x to a number in [1.5,2.5] by
 *              lgamma(1+s) = log(s) + lgamma(s)
 *      for example,
 *              lgamma(7.3) = log(6.3) + lgamma(6.3)
 *                          = log(6.3*5.3) + lgamma(5.3)
 *                          = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3)
 *   2. Polynomial approximation of lgamma around its
 *      minimun ymin=1.461632144968362245 to maintain monotonicity.
 *      On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use
 *              Let z = x-ymin;
 *              lgamma(x) = -1.214862905358496078218 + z^2*poly(z)
 *      where
 *              poly(z) is a 14 degree polynomial.
 *   2. Rational approximation in the primary interval [2,3]
 *      We use the following approximation:
 *              s = x-2.0;
 *              lgamma(x) = 0.5*s + s*P(s)/Q(s)
 *      with accuracy
 *              |P/Q - (lgamma(x)-0.5s)| < 2**-61.71
 *      Our algorithms are based on the following observation
 *
 *                             zeta(2)-1    2    zeta(3)-1    3
 * lgamma(2+s) = s*(1-Euler) + --------- * s  -  --------- * s  + ...
 *                                 2                 3
 *
 *      where Euler = 0.5771... is the Euler constant, which is very
 *      close to 0.5.
 *
 *   3. For x>=8, we have
 *      lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+....
 *      (better formula:
 *         lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...)
 *      Let z = 1/x, then we approximation
 *              f(z) = lgamma(x) - (x-0.5)(log(x)-1)
 *      by
 *                                  3       5             11
 *              w = w0 + w1*z + w2*z  + w3*z  + ... + w6*z
 *      where
 *              |w - f(z)| < 2**-58.74
 *
 *   4. For negative x, since (G is gamma function)
 *              -x*G(-x)*G(x) = pi/sin(pi*x),
 *      we have
 *              G(x) = pi/(sin(pi*x)*(-x)*G(-x))
 *      since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0
 *      Hence, for x<0, signgam = sign(sin(pi*x)) and
 *              lgamma(x) = log(|Gamma(x)|)
 *                        = log(pi/(|x*sin(pi*x)|)) - lgamma(-x);
 *      Note: one should avoid compute pi*(-x) directly in the
 *            computation of sin(pi*(-x)).
 *
 *   5. Special Cases
 *              lgamma(2+s) ~ s*(1-Euler) for tiny s
 *              lgamma(1) = lgamma(2) = 0
 *              lgamma(x) ~ -log(|x|) for tiny x
 *              lgamma(0) = lgamma(neg.integer) = inf and raise divide-by-zero
 *              lgamma(inf) = inf
 *              lgamma(-inf) = inf (bug for bug compatible with C99!?)
 *
 */

/* 0x400921FB, 0x54442D18 */

/* 0x3FB3C467, 0xE37DB0C8 */

/* 0x3FD4A34C, 0xC4A60FAD */

/* 0x3FB13E00, 0x1A5562A7 */

/* 0x3F951322, 0xAC92547B */

/* 0x3F7E404F, 0xB68FEFE8 */

/* 0x3F67ADD8, 0xCCB7926B */

/* 0x3F538A94, 0x116F3F5D */

/* 0x3F40B6C6, 0x89B99C00 */

/* 0x3F2CF2EC, 0xED10E54D */

/* 0x3F1C5088, 0x987DFB07 */

/* 0x3EFA7074, 0x428CFA52 */

/* 0x3F07858E, 0x90A45837 */

/* 0x3FF762D8, 0x6356BE3F */

/* 0xBFBF19B9, 0xBCC38A42 */

/* tt = -(tail of tf) */

/* 0xBC50C7CA, 0xA48A971F */

/* 0x3FDEF72B, 0xC8EE38A2 */

/* 0xBFC2E427, 0x8DC6C509 */

/* 0x3FB08B42, 0x94D5419B */

/* 0xBFA0C9A8, 0xDF35B713 */

/* 0x3F9266E7, 0x970AF9EC */

/* 0xBF851F9F, 0xBA91EC6A */

/* 0x3F78FCE0, 0xE370E344 */

/* 0xBF6E2EFF, 0xB3E914D7 */

/* 0x3F6282D3, 0x2E15C915 */

/* 0xBF56FE8E, 0xBF2D1AF1 */

/* 0x3F4CDF0C, 0xEF61A8E9 */

/* 0xBF41A610, 0x9C73E0EC */

/* 0x3F34AF6D, 0x6C0EBBF7 */

/* 0xBF347F24, 0xECC38C38 */

/* 0x3F35FD3E, 0xE8C2D3F4 */

/* 0xBFB3C467, 0xE37DB0C8 */

/* 0x3FE4401E, 0x8B005DFF */

/* 0x3FF7475C, 0xD119BD6F */

/* 0x3FEF4976, 0x44EA8450 */

/* 0x3FCD4EAE, 0xF6010924 */

/* 0x3F8B678B, 0xBF2BAB09 */

/* 0x4003A5D7, 0xC2BD619C */

/* 0x40010725, 0xA42B18F5 */

/* 0x3FE89DFB, 0xE45050AF */

/* 0x3FBAAE55, 0xD6537C88 */

/* 0x3F6A5ABB, 0x57D0CF61 */

/* 0xBFB3C467, 0xE37DB0C8 */

/* 0x3FCB848B, 0x36E20878 */

/* 0x3FD4D98F, 0x4F139F59 */

/* 0x3FC2BB9C, 0xBEE5F2F7 */

/* 0x3F9B481C, 0x7E939961 */

/* 0x3F5E26B6, 0x7368F239 */

/* 0x3F00BFEC, 0xDD17E945 */

/* 0x3FF645A7, 0x62C4AB74 */

/* 0x3FE71A18, 0x93D3DCDC */

/* 0x3FC601ED, 0xCCFBDF27 */

/* 0x3F9317EA, 0x742ED475 */

/* 0x3F497DDA, 0xCA41A95B */

/* 0x3EDEBAF7, 0xA5B38140 */

/* 0x3FDACFE3, 0x90C97D69 */

/* 0x3FB55555, 0x5555553B */

/* 0xBF66C16C, 0x16B02E5C */

/* 0x3F4A019F, 0x98CF38B6 */

/* 0xBF4380CB, 0x8C0FE741 */

/* 0x3F4B67BA, 0x4CDAD5D1 */

/* 0xBF5AB89D, 0x0B9E43E4 */

/* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */

/* spurious inexact if odd int */

/* x mod 2.0 */

/* case 4: */

/* purge off +-inf, NaN, +-0, tiny and negative arguments */

/* |x|<2**-70, return -log(|x|) */

/* -integer */

/* purge off 1 and 2 */

/* for x < 2.0 */

/* lgamma(x) = lgamma(x+1)-log(x) */

/* [1.7316,2] */

/* [1.23,1.73] */

/* parallel comp */

/* x < 8.0 */

/* lgamma(1+s) = log(s) + lgamma(s) */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* 8.0 <= x < 2**58 */

/* 2**58 <= x <= inf */


=== system/lib/libc/musl/src/math/lgammaf_r.c ===
SHA256: 5aa1db729889e0705ef94b2cb4d7ab5fa6a615d28fd74b7bdf7579a22f6e7ed4
Primary Git blob: 3f353f19b339f03cdbd022d24fc69284b9b2c3f7
/* origin: FreeBSD /usr/src/lib/msun/src/e_lgammaf_r.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x40490fdb */

/* 0x3d9e233f */

/* 0x3ea51a66 */

/* 0x3d89f001 */

/* 0x3ca89915 */

/* 0x3bf2027e */

/* 0x3b3d6ec6 */

/* 0x3a9c54a1 */

/* 0x3a05b634 */

/* 0x39679767 */

/* 0x38e28445 */

/* 0x37d383a2 */

/* 0x383c2c75 */

/* 0x3fbb16c3 */

/* 0xbdf8cdcd */

/* tt = -(tail of tf) */

/* 0x31e61c52 */

/* 0x3ef7b95e */

/* 0xbe17213c */

/* 0x3d845a15 */

/* 0xbd064d47 */

/* 0x3c93373d */

/* 0xbc28fcfe */

/* 0x3bc7e707 */

/* 0xbb7177fe */

/* 0x3b141699 */

/* 0xbab7f476 */

/* 0x3a66f867 */

/* 0xba0d3085 */

/* 0x39a57b6b */

/* 0xb9a3f927 */

/* 0x39afe9f7 */

/* 0xbd9e233f */

/* 0x3f2200f4 */

/* 0x3fba3ae7 */

/* 0x3f7a4bb2 */

/* 0x3e6a7578 */

/* 0x3c5b3c5e */

/* 0x401d2ebe */

/* 0x4008392d */

/* 0x3f44efdf */

/* 0x3dd572af */

/* 0x3b52d5db */

/* 0xbd9e233f */

/* 0x3e5c245a */

/* 0x3ea6cc7a */

/* 0x3e15dce6 */

/* 0x3cda40e4 */

/* 0x3af135b4 */

/* 0x3805ff67 */

/* 0x3fb22d3b */

/* 0x3f38d0c5 */

/* 0x3e300f6e */

/* 0x3c98bf54 */

/* 0x3a4beed6 */

/* 0x36f5d7bd */

/* 0x3ed67f1d */

/* 0x3daaaaab */

/* 0xbb360b61 */

/* 0x3a500cfd */

/* 0xba1c065c */

/* 0x3a5b3dd2 */

/* 0xbad5c4e8 */

/* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */

/* spurious inexact if odd int */

/* x mod 2.0 */

/* case 4: */

/* purge off +-inf, NaN, +-0, tiny and negative arguments */

/* |x| < 2**-21, return -log(|x|) */

/* -integer */

/* purge off 1 and 2 */

/* for x < 2.0 */

/* lgamma(x) = lgamma(x+1)-log(x) */

/* [1.7316,2] */

/* [1.23,1.73] */

/* parallel comp */

/* x < 8.0 */

/* lgamma(1+s) = log(s) + lgamma(s) */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* 8.0 <= x < 2**58 */

/* 2**58 <= x <= inf */


=== system/lib/libc/musl/src/math/lgammal.c ===
SHA256: 852284cc7fb67db860bcf39a3a33c74481ef28ffa7818a16de82d7e2d534c312
Primary Git blob: abbd4fc6f382613599058b0b518aaa16670e1304
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_lgammal.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* lgammal(x)
 * Reentrant version of the logarithm of the Gamma function
 * with user provide pointer for the sign of Gamma(x).
 *
 * Method:
 *   1. Argument Reduction for 0 < x <= 8
 *      Since gamma(1+s)=s*gamma(s), for x in [0,8], we may
 *      reduce x to a number in [1.5,2.5] by
 *              lgamma(1+s) = log(s) + lgamma(s)
 *      for example,
 *              lgamma(7.3) = log(6.3) + lgamma(6.3)
 *                          = log(6.3*5.3) + lgamma(5.3)
 *                          = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3)
 *   2. Polynomial approximation of lgamma around its
 *      minimun ymin=1.461632144968362245 to maintain monotonicity.
 *      On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use
 *              Let z = x-ymin;
 *              lgamma(x) = -1.214862905358496078218 + z^2*poly(z)
 *   2. Rational approximation in the primary interval [2,3]
 *      We use the following approximation:
 *              s = x-2.0;
 *              lgamma(x) = 0.5*s + s*P(s)/Q(s)
 *      Our algorithms are based on the following observation
 *
 *                             zeta(2)-1    2    zeta(3)-1    3
 * lgamma(2+s) = s*(1-Euler) + --------- * s  -  --------- * s  + ...
 *                                 2                 3
 *
 *      where Euler = 0.5771... is the Euler constant, which is very
 *      close to 0.5.
 *
 *   3. For x>=8, we have
 *      lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+....
 *      (better formula:
 *         lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...)
 *      Let z = 1/x, then we approximation
 *              f(z) = lgamma(x) - (x-0.5)(log(x)-1)
 *      by
 *                                  3       5             11
 *              w = w0 + w1*z + w2*z  + w3*z  + ... + w6*z
 *
 *   4. For negative x, since (G is gamma function)
 *              -x*G(-x)*G(x) = pi/sin(pi*x),
 *      we have
 *              G(x) = pi/(sin(pi*x)*(-x)*G(-x))
 *      since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0
 *      Hence, for x<0, signgam = sign(sin(pi*x)) and
 *              lgamma(x) = log(|Gamma(x)|)
 *                        = log(pi/(|x*sin(pi*x)|)) - lgamma(-x);
 *      Note: one should avoid compute pi*(-x) directly in the
 *            computation of sin(pi*(-x)).
 *
 *   5. Special Cases
 *              lgamma(2+s) ~ s*(1-Euler) for tiny s
 *              lgamma(1)=lgamma(2)=0
 *              lgamma(x) ~ -log(x) for tiny x
 *              lgamma(0) = lgamma(inf) = inf
 *              lgamma(-integer) = +-inf
 *
 */

/* lgam(1+x) = 0.5 x + x a(x)/b(x)
    -0.268402099609375 <= x <= 0
    peak relative error 6.6e-22 */

/* b5 =  1.000000000000000000000000000000000000000E0 */

/* double precision */

/* tt = (tail of tf), i.e. tf + tt has extended precision. */

/* lgam ( 1.4616321449683623412626595423257213284682E0 ) =
-1.2148629053584960809551455717769158215135617312999903886372437313313530E-1 */

/* lgam (x + tc) = tf + tt + x g(x)/h(x)
    -0.230003726999612341262659542325721328468 <= x
       <= 0.2699962730003876587373404576742786715318
     peak relative error 2.1e-21 */

/* h6 = 1.000000000000000000000000000000000000000E0 */

/* lgam (x+1) = -0.5 x + x u(x)/v(x)
    -0.100006103515625 <= x <= 0.231639862060546875
    peak relative error 1.3e-21 */

/* v6 =  1.000000000000000000000000000000000000000E0 */

/* lgam (x+2) = .5 x + x s(x)/r(x)
     0 <= x <= 1
     peak relative error 7.2e-22 */

/* r6 =  1.000000000000000000000000000000000000000E0 */

/* lgam(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x w(1/x^2)
    x >= 8
    Peak relative error 1.51e-21
w0 = LS2PI - 0.5 */

/* sin(pi*x) assuming x > 2^-1000, if sin(pi*x)==0 the sign is arbitrary */

/* spurious inexact if odd int */

/* x mod 2.0 */

/* case 4: */

/* purge off +-inf, NaN, +-0, tiny and negative arguments */

/* |x|<2**-63, return -log(|x|) */

/* -integer */

/* purge off 1 and 2 (so the sign is ok with downward rounding) */

/* x < 2.0 */

/* 8.99993896484375e-1 */

/* lgamma(x) = lgamma(x+1) - log(x) */

/* 7.31597900390625e-1 */

/* 2.31639862060546875e-1 */

/* x < 0.23 */

/* 1.73162841796875 */

/* [1.7316,2] */

/* 1.23162841796875 */

/* [1.23,1.73] */

/* [0.9, 1.23] */

/* 8.0 */

/* x < 8.0 */

/* lgamma(1+s) = log(s) + lgamma(s) */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* FALLTHRU */

/* 2^66 */

/* 8.0 <= x < 2**66 */

/* 2**66 <= x <= inf */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/llrint.c ===
SHA256: 16839c5a71ccb7f030d4d4663a1a75f5ca28ae307d85d1955e31f916cdd121f4
Primary Git blob: 4f583ae5536aa6152c3bab8671846da507f8f57e
/* uses LLONG_MAX > 2^53, see comments in lrint.c */


=== system/lib/libc/musl/src/math/llrintf.c ===
SHA256: a3085e54d25c37171a029fcb0cab475891dfd19bd44bdf51cb4efaa9607276cc
Primary Git blob: 96949a006ea88146af15d967fc01f90431e34d19
/* uses LLONG_MAX > 2^24, see comments in lrint.c */


=== system/lib/libc/musl/src/math/llrintl.c ===
SHA256: 05224713c222af3a5ad8d9f86db2ede48a5c2c681f592bdc4b94bfdfacd6aae1
Primary Git blob: 3449f6f2b400944f64076270433144626d9eb4b5
/*
see comments in lrint.c

Note that if LLONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64
then x == 2**63 - 0.5 is the only input that overflows and
raises inexact (with tonearest or upward rounding mode)
*/

/* conversion */


=== system/lib/libc/musl/src/math/log.c ===
SHA256: a0694d8587a0d145d0f8ae87cbffba014d7988bc2ebcbfad94cea73b394c9ecc
Primary Git blob: cc52585a949886be2788a80f46af23f0784fde7f
/*
 * Double-precision log(x) function.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* Top 16 bits of a double.  */

/* Handle close to 1.0 inputs separately.  */

/* Fix sign of zero with downward rounding when x==1.  */

/* Worst-case error is around 0.507 ULP.  */

/* B[0] == -0.5.  */

/* x < 0x1p-1022 or inf or nan.  */

/* log(inf) == inf.  */

/* x is subnormal, normalize it.  */

/* x = 2^k z; where z is in range [OFF,2*OFF) and exact.
	   The range is split into N subintervals.
	   The ith subinterval contains z and c is near its center.  */

/* arithmetic shift */

/* log(x) = log1p(z/c-1) + log(c) + k*Ln2.  */

/* r ~= z/c - 1, |r| < 1/(2*N).  */

/* rounding error: 0x1p-55/N.  */

/* rounding error: 0x1p-55/N + 0x1p-66.  */

/* hi + lo = r + log(c) + k*Ln2.  */

/* log(x) = lo + (log1p(r) - r) + hi.  */

/* rounding error: 0x1p-54/N^2.  */

/* Worst case error if |y| > 0x1p-5:
	   0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)
	   Worst case error if |y| > 0x1p-4:
	   0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma).  */


=== system/lib/libc/musl/src/math/log10.c ===
SHA256: ef9b4b1f0918cf1fcb797f9fa4d4ffe177bfa27f668d74a41d613bfbcd83850a
Primary Git blob: 81026876b223d4f56d6c2542b18898d6105aa34d
/* origin: FreeBSD /usr/src/lib/msun/src/e_log10.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * Return the base 10 logarithm of x.  See log.c for most comments.
 *
 * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2
 * as in log.c, then combine and scale in extra precision:
 *    log10(x) = (f - f*f/2 + r)/log(10) + k*log10(2)
 */

/* 0x3fdbcb7b, 0x15200000 */

/* 0x3dbb9438, 0xca9aadd5 */

/* 0x3FD34413, 0x509F6000 */

/* 0x3D59FEF3, 0x11F12B36 */

/* 3FE55555 55555593 */

/* 3FD99999 9997FA04 */

/* 3FD24924 94229359 */

/* 3FCC71C5 1D8E78AF */

/* 3FC74664 96CB03DE */

/* 3FC39A09 D078C69F */

/* 3FC2F112 DF3E5244 */

/* log(+-0)=-inf */

/* log(-#) = NaN */

/* subnormal number, scale x up */

/* reduce x into [sqrt(2)/2, sqrt(2)] */

/* See log2.c for details. */

/* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */

/* val_hi+val_lo ~ log10(1+f) + k*log10(2) */

/*
	 * Extra precision in for adding y is not strictly needed
	 * since there is no very large cancellation near x = sqrt(2) or
	 * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs
	 * with some parallelism and it reduces the error for many args.
	 */


=== system/lib/libc/musl/src/math/log10f.c ===
SHA256: b8de5c0f14be2c622eca1cb33e80e5b131576c7c229aeffb8ea9f1d61555f6b9
Primary Git blob: 9ca2f017da666e2a4da75df66f1ab846eb0537e9
/* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * See comments in log10.c.
 */

/* 0x3ede6000 */

/* 0xb804ead9 */

/* 0x3e9a2080 */

/* 0x355427db */

/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */

/* 0.66666662693 */

/* 0.40000972152 */

/* 0.28498786688 */

/* 0.24279078841 */

/* x < 2**-126  */

/* log(+-0)=-inf */

/* log(-#) = NaN */

/* subnormal number, scale up x */

/* reduce x into [sqrt(2)/2, sqrt(2)] */


=== system/lib/libc/musl/src/math/log10l.c ===
SHA256: d23e3d61fe4111628efdef794ae7cd614e3443a81f70742e29070f99fdd078c4
Primary Git blob: 63dcc286d6211d455f291dc9fff2704792a2d236
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Common logarithm, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, log10l();
 *
 * y = log10l( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns the base 10 logarithm of x.
 *
 * The argument is separated into its exponent and fractional
 * parts.  If the exponent is between -1 and +1, the logarithm
 * of the fraction is approximated by
 *
 *     log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
 *
 * Otherwise, setting  z = 2(x-1)/x+1),
 *
 *     log(x) = z + z**3 P(z)/Q(z).
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      0.5, 2.0     30000      9.0e-20     2.6e-20
 *    IEEE     exp(+-10000)  30000      6.0e-20     2.3e-20
 *
 * In the tests over the interval exp(+-10000), the logarithms
 * of the random arguments were uniformly distributed over
 * [-10000, +10000].
 *
 * ERROR MESSAGES:
 *
 * log singularity:  x = 0; returns MINLOG
 * log domain:       x < 0; returns MINLOG
 */

/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 6.2e-22
 */

/* 1.0000000000000000000000E0,*/

/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2),
 * where z = 2(x-1)/(x+1)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 6.16e-22
 */

/* 1.00000000000000000000E0L,*/

/* log10(2) */

/* log10(e) */

/* separate mantissa from exponent */

/* Note, frexp is used so that denormal numbers
	 * will be handled properly.
	 */

/* logarithm using log(x) = z + z**3 P(z)/Q(z),
	 * where z = 2(x-1)/x+1)
	 */

/* 2(2x-1)/(2x+1) */

/*  2 (x-1)/(x+1)   */

/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */

/* Multiply log of fraction by log10(e)
	 * and base 2 exponent by log10(2).
	 *
	 * ***CAUTION***
	 *
	 * This sequence of operations is critical and it may
	 * be horribly defeated by some compiler optimizers.
	 */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/log1p.c ===
SHA256: c76bbf714cd456a9f0de6e2c94853c27e7865581a2edfdef6d1f861739bbcb46
Primary Git blob: 0097134940378136f861708e6b952a8d67f76b3c
/* origin: FreeBSD /usr/src/lib/msun/src/s_log1p.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* double log1p(double x)
 * Return the natural logarithm of 1+x.
 *
 * Method :
 *   1. Argument Reduction: find k and f such that
 *                      1+x = 2^k * (1+f),
 *         where  sqrt(2)/2 < 1+f < sqrt(2) .
 *
 *      Note. If k=0, then f=x is exact. However, if k!=0, then f
 *      may not be representable exactly. In that case, a correction
 *      term is need. Let u=1+x rounded. Let c = (1+x)-u, then
 *      log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u),
 *      and add back the correction term c/u.
 *      (Note: when x > 2**53, one can simply return log(x))
 *
 *   2. Approximation of log(1+f): See log.c
 *
 *   3. Finally, log1p(x) = k*ln2 + log(1+f) + c/u. See log.c
 *
 * Special cases:
 *      log1p(x) is NaN with signal if x < -1 (including -INF) ;
 *      log1p(+INF) is +INF; log1p(-1) is -INF with signal;
 *      log1p(NaN) is that NaN with no signal.
 *
 * Accuracy:
 *      according to an error analysis, the error is always less than
 *      1 ulp (unit in the last place).
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 *
 * Note: Assuming log() return accurate answer, the following
 *       algorithm can be used to compute log1p(x) to within a few ULP:
 *
 *              u = 1+x;
 *              if(u==1.0) return x ; else
 *                         return log(u)*(x/(u-1.0));
 *
 *       See HP-15C Advanced Functions Handbook, p.193.
 */

/* 3fe62e42 fee00000 */

/* 3dea39ef 35793c76 */

/* 3FE55555 55555593 */

/* 3FD99999 9997FA04 */

/* 3FD24924 94229359 */

/* 3FCC71C5 1D8E78AF */

/* 3FC74664 96CB03DE */

/* 3FC39A09 D078C69F */

/* 3FC2F112 DF3E5244 */

/* 1+x < sqrt(2)+ */

/* x <= -1.0 */

/* log1p(-1) = -inf */

/* log1p(x<-1) = NaN */

/* |x| < 2**-53 */

/* underflow if subnormal */

/* sqrt(2)/2- <= 1+x < sqrt(2)+ */

/* correction term ~ log(1+x)-log(u), avoid underflow in c/u */

/* reduce u into [sqrt(2)/2, sqrt(2)] */


=== system/lib/libc/musl/src/math/log1pf.c ===
SHA256: 6c01aff9fcee1dcaca4d4581f17357e0f069643321c00288c672adc3521d0cc8
Primary Git blob: 23985c35675842d925bbc3c1475bd419926e0fda
/* origin: FreeBSD /usr/src/lib/msun/src/s_log1pf.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* 0x3f317180 */

/* 0x3717f7d1 */

/* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */

/* 0.66666662693 */

/* 0.40000972152 */

/* 0.28498786688 */

/* 0.24279078841 */

/* 1+x < sqrt(2)+  */

/* x <= -1.0 */

/* log1p(-1)=+inf */

/* log1p(x<-1)=NaN */

/* |x| < 2**-24 */

/* underflow if subnormal */

/* sqrt(2)/2- <= 1+x < sqrt(2)+ */

/* correction term ~ log(1+x)-log(u), avoid underflow in c/u */

/* reduce u into [sqrt(2)/2, sqrt(2)] */


=== system/lib/libc/musl/src/math/log1pl.c ===
SHA256: 3846b55cbd55e3d3f90d7484216663030ec98c4c353e644ce3c4e3122080e4c4
Primary Git blob: 141b5f0b0c295a38d7ab1e1793bdbe2ec35fa2ae
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/s_log1pl.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Relative error logarithm
 *      Natural logarithm of 1+x, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, log1pl();
 *
 * y = log1pl( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns the base e (2.718...) logarithm of 1+x.
 *
 * The argument 1+x is separated into its exponent and fractional
 * parts.  If the exponent is between -1 and +1, the logarithm
 * of the fraction is approximated by
 *
 *     log(1+x) = x - 0.5 x^2 + x^3 P(x)/Q(x).
 *
 * Otherwise, setting  z = 2(x-1)/x+1),
 *
 *     log(x) = z + z^3 P(z)/Q(z).
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE     -1.0, 9.0    100000      8.2e-20    2.5e-20
 */

/* Coefficients for log(1+x) = x - x^2 / 2 + x^3 P(x)/Q(x)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 2.32e-20
 */

/* 1.0000000000000000000000E0,*/

/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2),
 * where z = 2(x-1)/(x+1)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 6.16e-22
 */

/* 1.00000000000000000000E0L,*/

/* Test for domain errors.  */

/* -inf with divbyzero */

/* nan with invalid */

/* Separate mantissa from exponent.
	   Use frexp so that denormal numbers will be handled properly.  */

/* logarithm using log(x) = z + z^3 P(z)/Q(z),
	   where z = 2(x-1)/x+1)  */

/* 2(2x-1)/(2x+1) */

/*  2 (x-1)/(x+1)   */

/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/log2.c ===
SHA256: 281e4fc0f737419e245019d8bc8a8ca53032c2d88c31d08561e9e59dcb4b4640
Primary Git blob: 1276ed4e310097a7acf622f060f5feb9f9806064
/*
 * Double-precision log2(x) function.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* Top 16 bits of a double.  */

/* Handle close to 1.0 inputs separately.  */

/* Fix sign of zero with downward rounding when x==1.  */

/* rounding error: 0x1p-62.  */

/* Worst-case error is less than 0.54 ULP (0.55 ULP without fma).  */

/* x < 0x1p-1022 or inf or nan.  */

/* log(inf) == inf.  */

/* x is subnormal, normalize it.  */

/* x = 2^k z; where z is in range [OFF,2*OFF) and exact.
	   The range is split into N subintervals.
	   The ith subinterval contains z and c is near its center.  */

/* arithmetic shift */

/* log2(x) = log2(z/c) + log2(c) + k.  */

/* r ~= z/c - 1, |r| < 1/(2*N).  */

/* rounding error: 0x1p-55/N.  */

/* rounding error: 0x1p-55/N + 0x1p-65.  */

/* hi + lo = r/ln2 + log2(c) + k.  */

/* log2(r+1) = r/ln2 + r^2*poly(r).  */

/* Evaluation is optimized assuming superscalar pipelined execution.  */

/* rounding error: 0x1p-54/N^2.  */

/* Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).
	   ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma).  */


=== system/lib/libc/musl/src/math/log2_data.c ===
SHA256: 5a62bb213f19dc1364cddb612e3d13831e382f5ae6f7fafd7064362f53478dfb
Primary Git blob: 3dd1ca5146cf4ff7029e0596bcddf5e3a195a502
/*
 * Data for log2.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

// First coefficient: 0x1.71547652b82fe1777d0ffda0d24p0

// relative error: 0x1.2fad8188p-63

// in -0x1.5b51p-5 0x1.6ab2p-5

// relative error: 0x1.a72c2bf8p-58

// abs error: 0x1.67a552c8p-66

// in -0x1.f45p-8 0x1.f45p-8

/* Algorithm:

	x = 2^k z
	log2(x) = k + log2(c) + log2(z/c)
	log2(z/c) = poly(z/c - 1)

where z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls
into the ith one, then table entries are computed as

	tab[i].invc = 1/c
	tab[i].logc = (double)log2(c)
	tab2[i].chi = (double)c
	tab2[i].clo = (double)(c - (double)c)

where c is near the center of the subinterval and is chosen by trying +-2^29
floating point invc candidates around 1/center and selecting one for which

	1) the rounding error in 0x1.8p10 + logc is 0,
	2) the rounding error in z - chi - clo is < 0x1p-64 and
	3) the rounding error in (double)log2(c) is minimized (< 0x1p-68).

Note: 1) ensures that k + logc can be computed without rounding error, 2)
ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a
single rounding error when there is no fast fma for z*invc - 1, 3) ensures
that logc + poly(z/c - 1) has small error, however near x == 1 when
|log2(x)| < 0x1p-4, this is not enough so that is special cased.  */


=== system/lib/libc/musl/src/math/log2_data.h ===
SHA256: b56e1a56f73a8700caa9787cd399fecf7f96038af56c2a590aeb6f0f8662ea8e
Primary Git blob: 276a786d1424e41eed9e1d529c199de686618b95
/*
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


=== system/lib/libc/musl/src/math/log2_small.c ===
SHA256: f80ab2145f156b8a986cd1303b9753d10631e75a03502a7067c4a38c4849484e
Primary Git blob: 0aafad4b86c1cd3bf7b69090534aa1f5a05fda36
/* origin: FreeBSD /usr/src/lib/msun/src/e_log2.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * Return the base 2 logarithm of x.  See log.c for most comments.
 *
 * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2
 * as in log.c, then combine and scale in extra precision:
 *    log2(x) = (f - f*f/2 + r)/log(2) + k
 */

/* 0x3ff71547, 0x65200000 */

/* 0x3de705fc, 0x2eefa200 */

/* 3FE55555 55555593 */

/* 3FD99999 9997FA04 */

/* 3FD24924 94229359 */

/* 3FCC71C5 1D8E78AF */

/* 3FC74664 96CB03DE */

/* 3FC39A09 D078C69F */

/* 3FC2F112 DF3E5244 */

/* log(+-0)=-inf */

/* log(-#) = NaN */

/* subnormal number, scale x up */

/* reduce x into [sqrt(2)/2, sqrt(2)] */

/*
	 * f-hfsq must (for args near 1) be evaluated in extra precision
	 * to avoid a large cancellation when x is near sqrt(2) or 1/sqrt(2).
	 * This is fairly efficient since f-hfsq only depends on f, so can
	 * be evaluated in parallel with R.  Not combining hfsq with R also
	 * keeps R small (though not as small as a true `lo' term would be),
	 * so that extra precision is not needed for terms involving R.
	 *
	 * Compiler bugs involving extra precision used to break Dekker's
	 * theorem for spitting f-hfsq as hi+lo, unless double_t was used
	 * or the multi-precision calculations were avoided when double_t
	 * has extra precision.  These problems are now automatically
	 * avoided as a side effect of the optimization of combining the
	 * Dekker splitting step with the clear-low-bits step.
	 *
	 * y must (for args near sqrt(2) and 1/sqrt(2)) be added in extra
	 * precision to avoid a very large cancellation when x is very near
	 * these values.  Unlike the above cancellations, this problem is
	 * specific to base 2.  It is strange that adding +-1 is so much
	 * harder than adding +-ln2 or +-log10_2.
	 *
	 * This uses Dekker's theorem to normalize y+val_hi, so the
	 * compiler bugs are back in some configurations, sigh.  And I
	 * don't want to used double_t to avoid them, since that gives a
	 * pessimization and the support for avoiding the pessimization
	 * is not yet available.
	 *
	 * The multi-precision calculations for the multiplications are
	 * routine.
	 */

/* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */

/* spadd(val_hi, val_lo, y), except for not using double_t: */


=== system/lib/libc/musl/src/math/log2f.c ===
SHA256: f2393ef18e78e6dc540e7349dbfea000018246d64fca3eefe73f11a286403352
Primary Git blob: c368f88f33f5cc4eb261a247ffebf6df760c63ce
/*
 * Single-precision log2 function.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/*
LOG2F_TABLE_BITS = 4
LOG2F_POLY_ORDER = 4

ULP error: 0.752 (nearest rounding.)
Relative error: 1.9 * 2^-26 (before rounding.)
*/

/* Fix sign of zero with downward rounding when x==1.  */

/* x < 0x1p-126 or inf or nan.  */

/* log2(inf) == inf.  */

/* x is subnormal, normalize it.  */

/* x = 2^k z; where z is in range [OFF,2*OFF] and exact.
	   The range is split into N subintervals.
	   The ith subinterval contains z and c is near its center.  */

/* arithmetic shift */

/* log2(x) = log1p(z/c-1)/ln2 + log2(c) + k */

/* Pipelined polynomial evaluation to approximate log1p(r)/ln2.  */


=== system/lib/libc/musl/src/math/log2f_data.c ===
SHA256: 9261d7fdef29db26bd75310f029823593639ecf7c1cc089a6014623d49d21abe
Primary Git blob: 24e450f1ec3998f9eca8b2f696c06782fb4d2b7d
/*
 * Data definition for log2f.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


=== system/lib/libc/musl/src/math/log2f_data.h ===
SHA256: cb65ee48f557b19c8a6366a05f16ffba38aa46b00c4c136faf2dea8f53675a9b
Primary Git blob: 4fa489560d4aa47a5661047f86fd60d03e9bae56
/*
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


=== system/lib/libc/musl/src/math/log2l.c ===
SHA256: c3294ef6fcf96c061c4511fb3f6cd2886b2f513938deadcfb16fc19fb2a9ff03
Primary Git blob: 722b451a026ae2ccd1b70381c4a87b7936ddb3c2
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log2l.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Base 2 logarithm, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, log2l();
 *
 * y = log2l( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns the base 2 logarithm of x.
 *
 * The argument is separated into its exponent and fractional
 * parts.  If the exponent is between -1 and +1, the (natural)
 * logarithm of the fraction is approximated by
 *
 *     log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
 *
 * Otherwise, setting  z = 2(x-1)/x+1),
 *
 *     log(x) = z + z**3 P(z)/Q(z).
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      0.5, 2.0     30000      9.8e-20     2.7e-20
 *    IEEE     exp(+-10000)  70000      5.4e-20     2.3e-20
 *
 * In the tests over the interval exp(+-10000), the logarithms
 * of the random arguments were uniformly distributed over
 * [-10000, +10000].
 */

/* Coefficients for ln(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 6.2e-22
 */

/* 1.0000000000000000000000E0,*/

/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2),
 * where z = 2(x-1)/(x+1)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 6.16e-22
 */

/* 1.00000000000000000000E0L,*/

/* log2(e) - 1 */

/* -inf with divbyzero */

/* nan with invalid */

/* separate mantissa from exponent */

/* Note, frexp is used so that denormal numbers
	 * will be handled properly.
	 */

/* logarithm using log(x) = z + z**3 P(z)/Q(z),
	 * where z = 2(x-1)/x+1)
	 */

/* 2(2x-1)/(2x+1) */

/*  2 (x-1)/(x+1)   */

/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */

/* Multiply log of fraction by log2(e)
	 * and base 2 exponent by 1
	 *
	 * ***CAUTION***
	 *
	 * This sequence of operations is critical and it may
	 * be horribly defeated by some compiler optimizers.
	 */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/log_data.c ===
SHA256: e96bcd99d88fc57e0f3686299014f4b949a6212603ce237f39e16cedc155617a
Primary Git blob: 1a6ec712a0ceb595217d4c75909948f79facd295
/*
 * Data for log.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

// relative error: 0x1.c04d76cp-63

// in -0x1p-4 0x1.09p-4 (|log(1+x)| > 0x1p-4 outside the interval)

// relative error: 0x1.926199e8p-56

// abs error: 0x1.882ff33p-65

// in -0x1.fp-9 0x1.fp-9

/* Algorithm:

	x = 2^k z
	log(x) = k ln2 + log(c) + log(z/c)
	log(z/c) = poly(z/c - 1)

where z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls
into the ith one, then table entries are computed as

	tab[i].invc = 1/c
	tab[i].logc = (double)log(c)
	tab2[i].chi = (double)c
	tab2[i].clo = (double)(c - (double)c)

where c is near the center of the subinterval and is chosen by trying +-2^29
floating point invc candidates around 1/center and selecting one for which

	1) the rounding error in 0x1.8p9 + logc is 0,
	2) the rounding error in z - chi - clo is < 0x1p-66 and
	3) the rounding error in (double)log(c) is minimized (< 0x1p-66).

Note: 1) ensures that k*ln2hi + logc can be computed without rounding error,
2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to
a single rounding error when there is no fast fma for z*invc - 1, 3) ensures
that logc + poly(z/c - 1) has small error, however near x == 1 when
|log(x)| < 0x1p-4, this is not enough so that is special cased.  */


=== system/lib/libc/musl/src/math/log_data.h ===
SHA256: a8dced6f0821f30cad040ba326b03e419fbe0a750ed8f3b0d7145992bee4bccc
Primary Git blob: 1be22ab242a3699fe192ec7bb636d29babca5074
/*
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* First coefficient is 1.  */


=== system/lib/libc/musl/src/math/log_small.c ===
SHA256: 017fe474291d5cbad5f2b57c53200ca645248dd7ea87e149ddfdf78ffd32af0d
Primary Git blob: e61e113d41af91f86d4482a979c84966be66fe33
/* origin: FreeBSD /usr/src/lib/msun/src/e_log.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* log(x)
 * Return the logarithm of x
 *
 * Method :
 *   1. Argument Reduction: find k and f such that
 *                      x = 2^k * (1+f),
 *         where  sqrt(2)/2 < 1+f < sqrt(2) .
 *
 *   2. Approximation of log(1+f).
 *      Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
 *               = 2s + 2/3 s**3 + 2/5 s**5 + .....,
 *               = 2s + s*R
 *      We use a special Remez algorithm on [0,0.1716] to generate
 *      a polynomial of degree 14 to approximate R The maximum error
 *      of this polynomial approximation is bounded by 2**-58.45. In
 *      other words,
 *                      2      4      6      8      10      12      14
 *          R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s  +Lg6*s  +Lg7*s
 *      (the values of Lg1 to Lg7 are listed in the program)
 *      and
 *          |      2          14          |     -58.45
 *          | Lg1*s +...+Lg7*s    -  R(z) | <= 2
 *          |                             |
 *      Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
 *      In order to guarantee error in log below 1ulp, we compute log
 *      by
 *              log(1+f) = f - s*(f - R)        (if f is not too large)
 *              log(1+f) = f - (hfsq - s*(hfsq+R)).     (better accuracy)
 *
 *      3. Finally,  log(x) = k*ln2 + log(1+f).
 *                          = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
 *         Here ln2 is split into two floating point number:
 *                      ln2_hi + ln2_lo,
 *         where n*ln2_hi is always exact for |n| < 2000.
 *
 * Special cases:
 *      log(x) is NaN with signal if x < 0 (including -INF) ;
 *      log(+INF) is +INF; log(0) is -INF with signal;
 *      log(NaN) is that NaN with no signal.
 *
 * Accuracy:
 *      according to an error analysis, the error is always less than
 *      1 ulp (unit in the last place).
 *
 * Constants:
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

/* 3fe62e42 fee00000 */

/* 3dea39ef 35793c76 */

/* 3FE55555 55555593 */

/* 3FD99999 9997FA04 */

/* 3FD24924 94229359 */

/* 3FCC71C5 1D8E78AF */

/* 3FC74664 96CB03DE */

/* 3FC39A09 D078C69F */

/* 3FC2F112 DF3E5244 */

/* log(+-0)=-inf */

/* log(-#) = NaN */

/* subnormal number, scale x up */

/* reduce x into [sqrt(2)/2, sqrt(2)] */


=== system/lib/libc/musl/src/math/logb.c ===
SHA256: 46f89d69993da5a4b329d8958fbf1c93427b85cca53e45b4d4aa9a91bcc043b1
Primary Git blob: 7f8bdfae19f8ca0a85b611d38a73695ccf588e43
/*
special cases:
	logb(+-0) = -inf, and raise divbyzero
	logb(+-inf) = +inf
	logb(nan) = nan
*/


=== system/lib/libc/musl/src/math/logf.c ===
SHA256: eecf8e5dd0afd5f64f938ccae07c85b0a8e82919f5d4269936a3b8493fb64e47
Primary Git blob: e4c2237caa2eb51c08626731fd315fba21f92618
/*
 * Single-precision log function.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/*
LOGF_TABLE_BITS = 4
LOGF_POLY_ORDER = 4

ULP error: 0.818 (nearest rounding.)
Relative error: 1.957 * 2^-26 (before rounding.)
*/

/* Fix sign of zero with downward rounding when x==1.  */

/* x < 0x1p-126 or inf or nan.  */

/* log(inf) == inf.  */

/* x is subnormal, normalize it.  */

/* x = 2^k z; where z is in range [OFF,2*OFF] and exact.
	   The range is split into N subintervals.
	   The ith subinterval contains z and c is near its center.  */

/* arithmetic shift */

/* log(x) = log1p(z/c-1) + log(c) + k*Ln2 */

/* Pipelined polynomial evaluation to approximate log1p(r).  */


=== system/lib/libc/musl/src/math/logf_data.c ===
SHA256: 60b08342fcef877b393a76fc36d92c576d6340ce153459aad03aad3d4716f9b5
Primary Git blob: 857221f790157836a49e014abf4d7989522c3773
/*
 * Data definition for logf.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


=== system/lib/libc/musl/src/math/logf_data.h ===
SHA256: 80176d1f045f162e917ca5c2879994ab0ed9e27b479086d752e5793c91135adf
Primary Git blob: 00cff6f81d4383567028a02293a56bddb7f70c67
/*
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* First order coefficient is 1.  */


=== system/lib/libc/musl/src/math/logl.c ===
SHA256: e1612b2bb9a010c1914beb93fa242981f69f323392bd9816415cafaaec0d94b0
Primary Git blob: 5d5365929e62a351c4544bd9e6aace6e02834292
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_logl.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Natural logarithm, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, logl();
 *
 * y = logl( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns the base e (2.718...) logarithm of x.
 *
 * The argument is separated into its exponent and fractional
 * parts.  If the exponent is between -1 and +1, the logarithm
 * of the fraction is approximated by
 *
 *     log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
 *
 * Otherwise, setting  z = 2(x-1)/(x+1),
 *
 *     log(x) = log(1+z/2) - log(1-z/2) = z + z**3 P(z)/Q(z).
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      0.5, 2.0    150000      8.71e-20    2.75e-20
 *    IEEE     exp(+-10000) 100000      5.39e-20    2.34e-20
 *
 * In the tests over the interval exp(+-10000), the logarithms
 * of the random arguments were uniformly distributed over
 * [-10000, +10000].
 */

/* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 2.32e-20
 */

/* 1.0000000000000000000000E0,*/

/* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2),
 * where z = 2(x-1)/(x+1)
 * 1/sqrt(2) <= x < sqrt(2)
 * Theoretical peak relative error = 6.16e-22
 */

/* 1.00000000000000000000E0L,*/

/* -inf with divbyzero */

/* nan with invalid */

/* separate mantissa from exponent */

/* Note, frexp is used so that denormal numbers
	 * will be handled properly.
	 */

/* logarithm using log(x) = z + z**3 P(z)/Q(z),
	 * where z = 2(x-1)/(x+1)
	 */

/* 2(2x-1)/(2x+1) */

/*  2 (x-1)/(x+1)   */

/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */

/* Note, the sum of above terms does not exceed x/4,
	 * so it contributes at most about 1/4 lsb to the error.
	 */

/* This sum has an error of 1/2 lsb. */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/lrint.c ===
SHA256: ef099c61a442a79c5e7afc11ddc6915e31022a1b8c1c44d74dd03184f068d02b
Primary Git blob: ddee7a0d9a689c5e062ad6ef2a59ae6c5cad2683
/*
If the result cannot be represented (overflow, nan), then
lrint raises the invalid exception.

Otherwise if the input was not an integer then the inexact
exception is raised.

C99 is a bit vague about whether inexact exception is
allowed to be raised when invalid is raised.
(F.9 explicitly allows spurious inexact exceptions, F.9.6.5
does not make it clear if that rule applies to lrint, but
IEEE 754r 7.8 seems to forbid spurious inexact exception in
the ineger conversion functions)

So we try to make sure that no spurious inexact exception is
raised in case of an overflow.

If the bit size of long > precision of double, then there
cannot be inexact rounding in case the result overflows,
otherwise LONG_MAX and LONG_MIN can be represented exactly
as a double.
*/

/* avoid stack frame in lrint */

/* conversion */

/* |x| < 0x7ffffc00, no overflow */


=== system/lib/libc/musl/src/math/lrintf.c ===
SHA256: d6673476094b190bd80f92bf89d3c6254beaf1c33fc7f7245059bcdcd7f4c6c9
Primary Git blob: ca0b6a46aaed3cf97d61724923593ea1b9d7aaf3
/* uses LONG_MAX > 2^24, see comments in lrint.c */


=== system/lib/libc/musl/src/math/lrintl.c ===
SHA256: f200d3d4a04d1461adfef5d8212a07940a5611509c4b424bcf7369540c4809f8
Primary Git blob: b2a8106d7c6a1710eea10791fdf72d88df541d95
/*
see comments in lrint.c

Note that if LONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64
then x == 2**63 - 0.5 is the only input that overflows and
raises inexact (with tonearest or upward rounding mode)
*/

/* conversion */


=== system/lib/libc/musl/src/math/modf.c ===
SHA256: 9681ec8b49299a6fc2b2592241232535a1bc8e785f149efadfbb7637d006ca00
Primary Git blob: 1c8a1db90db7b4b61c5ec4271f184308690704db
/* no fractional part */

/* nan */

/* no integral part*/


=== system/lib/libc/musl/src/math/modff.c ===
SHA256: a22d1b522e59fc08400cf79523fd631891bc67ff60099df7b651887811e05112
Primary Git blob: 639514effafcc91997d53f4b8528e16b21440a9e
/* no fractional part */

/* nan */

/* no integral part */


=== system/lib/libc/musl/src/math/modfl.c ===
SHA256: 7071f715cab5797d2ae6085292f03b82ab53a3af25367966a2f0bf103a07956e
Primary Git blob: a47b1924f75d1125b712e3ccf5b0f39af27fd8f2
/* no fractional part */

/* no integral part*/

/* raises spurious inexact */


=== system/lib/libc/musl/src/math/nearbyint.c ===
SHA256: 0d0e0f810ad45a94feda189045f73ecc9097c20a56165ab56d3e40459c13f8ef
Primary Git blob: f4e8aac4f0118d7d48d1d6a8e4af0fec048ee62a
/* nearbyint is the same as rint, but it must not raise the inexact exception */


=== system/lib/libc/musl/src/math/nextafter.c ===
SHA256: e3ad4982e7e7b77ab6c23c3199fad3f2baa878f709424d598e2aa7a968eb31a1
Primary Git blob: ab5795a47a93e36c8c461d8a4be6621b582ae077
/* raise overflow if ux.f is infinite and x is finite */

/* raise underflow if ux.f is subnormal or zero */


=== system/lib/libc/musl/src/math/nextafterf.c ===
SHA256: d4ef2208316c8d18a2c076d899fa798376be2d7a159569c50222c99f5bca6fef
Primary Git blob: 75a09f7d1cf115d9a5d5dfeda9b12d42de269904
/* raise overflow if ux.f is infinite and x is finite */

/* raise underflow if ux.f is subnormal or zero */


=== system/lib/libc/musl/src/math/nextafterl.c ===
SHA256: 909b5a2688783331317349a8831bd58feeaf6d5b12dc6e944bbafb79f8d9d553
Primary Git blob: 37e858fb4982a775cc4099738c539c8bd2f25d76
/* raise overflow if ux is infinite and x is finite */

/* raise underflow if ux is subnormal or zero */

/* raise overflow if ux is infinite and x is finite */

/* raise underflow if ux is subnormal or zero */


=== system/lib/libc/musl/src/math/nexttoward.c ===
SHA256: ad4a0c12aae4a1d1c52abb2c38bdc025228883844706a606f4f763f24be12382
Primary Git blob: 827ee5c3c23ab0d9c33ff4205835bf068f0320e8
/* raise overflow if ux.f is infinite and x is finite */

/* raise underflow if ux.f is subnormal or zero */


=== system/lib/libc/musl/src/math/nexttowardf.c ===
SHA256: 5041be5f1cfd74da514cda3b1165390c62a5fe25892032eccdcdf04f07cec9a0
Primary Git blob: bbf172f9e65573e9059d26ea574aa8a96dfdef43
/* raise overflow if ux.f is infinite and x is finite */

/* raise underflow if ux.f is subnormal or zero */


=== system/lib/libc/musl/src/math/pow.c ===
SHA256: b06f0a08d74fcff8cced7afa2c0e47e301e3e8a19c0de5becdec28cd7b014027
Primary Git blob: 694c2ef64d008cf78696a6d660353e83792d22f3
/*
 * Double-precision x^y function.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/*
Worst-case error: 0.54 ULP (~= ulperr_exp + 1024*Ln2*relerr_log*2^53)
relerr_log: 1.3 * 2^-68 (Relative error of log, 1.5 * 2^-68 without fma)
ulperr_exp: 0.509 ULP (ULP error of exp, 0.511 ULP without fma)
*/

/* Top 12 bits of a double (sign and exponent bits).  */

/* Compute y+TAIL = log(x) where the rounded result is y and TAIL has about
   additional 15 bits precision.  IX is the bit representation of x, but
   normalized in the subnormal range using the sign bit for the exponent.  */

/* double_t for better performance on targets with FLT_EVAL_METHOD==2.  */

/* x = 2^k z; where z is in range [OFF,2*OFF) and exact.
	   The range is split into N subintervals.
	   The ith subinterval contains z and c is near its center.  */

/* arithmetic shift */

/* log(x) = k*Ln2 + log(c) + log1p(z/c-1).  */

/* Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and
     |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.  */

/* Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.  */

/* k*Ln2 + log(c) + r.  */

/* Evaluation is optimized assuming superscalar pipelined execution.  */

/* A[0] = -0.5.  */

/* k*Ln2 + log(c) + r + A[0]*r*r.  */

/* p = log1p(r) - r - A[0]*r*r.  */

/* Handle cases that may overflow or underflow when computing the result that
   is scale*(1+TMP) without intermediate rounding.  The bit representation of
   scale is in SBITS, however it has a computed exponent that may have
   overflown into the sign bit so that needs to be adjusted before using it as
   a double.  (int32_t)KI is the k used in the argument reduction and exponent
   adjustment of scale, positive k here means the result may overflow and
   negative k means the result may underflow.  */

/* k > 0, the exponent of scale might have overflowed by <= 460.  */

/* k < 0, need special care in the subnormal range.  */

/* Note: sbits is signed scale.  */

/* Round y to the right precision before scaling it into the subnormal
		   range to avoid double rounding that can cause 0.5+E/2 ulp error where
		   E is the worst-case ulp error outside the subnormal range.  So this
		   is only useful if the goal is better than 1 ulp worst-case error.  */

/* Fix the sign of 0.  */

/* The underflow exception needs to be signaled explicitly.  */

/* Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.
   The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.  */

/* double_t for better performance on targets with FLT_EVAL_METHOD==2.  */

/* Avoid spurious underflow for tiny x.  */

/* Note: 0 is common input.  */

/* Note: inf and nan are already handled.  */

/* Large x is special cased below.  */

/* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].  */

/* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].  */

/* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.  */

/* z - kd is in [-1, 1] in non-nearest rounding modes.  */

/* The code assumes 2^-200 < |xtail| < 2^-8/N.  */

/* 2^(k/N) ~= scale * (1 + tail).  */

/* This is only a valid scale when -1023*N < k < 1024*N.  */

/* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).  */

/* Evaluation is optimized assuming superscalar pipelined execution.  */

/* Without fma the worst case error is 0.25/N ulp larger.  */

/* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.  */

/* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there
	   is no spurious underflow here even without fma.  */

/* Returns 0 if not int, 1 if odd int, 2 if even int.  The argument is
   the bit representation of a non-zero finite floating-point value.  */

/* Returns 1 if input is the bit representation of 0, infinity or nan.  */

/* Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0
		   and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.  */

/* Special cases: (x < 0x1p-126 or inf or nan) or
		   (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).  */

/* |x|<1 && y==inf or |x|>1 && y==-inf.  */

/* Without the barrier some versions of clang hoist the 1/x2 and
			   thus division by zero exception can be signaled spuriously.  */

/* Here x and y are non-zero finite.  */

/* Finite x < 0.  */

/* Note: sign_bias == 0 here because y is not odd.  */

/* |y| < 2^-65, x^y ~= 1 + y*log(x).  */

/* Normalize subnormal x so exponent becomes negative.  */

/* |elo| < |ehi| * 2^-25.  */


=== system/lib/libc/musl/src/math/pow_data.c ===
SHA256: 2052ec913f9b4a2170a98a6fcbcd7694f5dec220036b00c36106a2b4b65a4c55
Primary Git blob: 81e760de196e4d11bc04093bacdef0bf68f07e91
/*
 * Data for the log part of pow.
 *
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

// relative error: 0x1.11922ap-70

// in -0x1.6bp-8 0x1.6bp-8

// Coefficients are scaled to match the scaling during evaluation.

/* Algorithm:

	x = 2^k z
	log(x) = k ln2 + log(c) + log(z/c)
	log(z/c) = poly(z/c - 1)

where z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals
and z falls into the ith one, then table entries are computed as

	tab[i].invc = 1/c
	tab[i].logc = round(0x1p43*log(c))/0x1p43
	tab[i].logctail = (double)(log(c) - logc)

where c is chosen near the center of the subinterval such that 1/c has only a
few precision bits so z/c - 1 is exactly representible as double:

	1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2

Note: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97,
the last few bits of logc are rounded away so k*ln2hi + logc has no rounding
error and the interval for z is selected such that near x == 1, where log(x)
is tiny, large cancellation error is avoided in logc + poly(z/c - 1).  */


=== system/lib/libc/musl/src/math/pow_data.h ===
SHA256: 5014345a7958adcf6ff835b5e96afa99dd5a98c40dfe968442288e002b8e01a3
Primary Git blob: 5d609ae80ec210badf3f705417e80d0f31da9f51
/*
 * Copyright (c) 2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/* First coefficient is 1.  */

/* Note: the pad field is unused, but allows slightly faster indexing.  */


=== system/lib/libc/musl/src/math/pow_small.c ===
SHA256: 2a1a2469efafd354c3acc689a14e0c498c94d3577c7bd746462e1b644e3c379d
Primary Git blob: b66f632d8eea9fce118c087677c755f391c6df85
/* origin: FreeBSD /usr/src/lib/msun/src/e_pow.c */

/*
 * ====================================================
 * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* pow(x,y) return x**y
 *
 *                    n
 * Method:  Let x =  2   * (1+f)
 *      1. Compute and return log2(x) in two pieces:
 *              log2(x) = w1 + w2,
 *         where w1 has 53-24 = 29 bit trailing zeros.
 *      2. Perform y*log2(x) = n+y' by simulating muti-precision
 *         arithmetic, where |y'|<=0.5.
 *      3. Return x**y = 2**n*exp(y'*log2)
 *
 * Special cases:
 *      1.  (anything) ** 0  is 1
 *      2.  1 ** (anything)  is 1
 *      3.  (anything except 1) ** NAN is NAN
 *      4.  NAN ** (anything except 0) is NAN
 *      5.  +-(|x| > 1) **  +INF is +INF
 *      6.  +-(|x| > 1) **  -INF is +0
 *      7.  +-(|x| < 1) **  +INF is +0
 *      8.  +-(|x| < 1) **  -INF is +INF
 *      9.  -1          ** +-INF is 1
 *      10. +0 ** (+anything except 0, NAN)               is +0
 *      11. -0 ** (+anything except 0, NAN, odd integer)  is +0
 *      12. +0 ** (-anything except 0, NAN)               is +INF, raise divbyzero
 *      13. -0 ** (-anything except 0, NAN, odd integer)  is +INF, raise divbyzero
 *      14. -0 ** (+odd integer) is -0
 *      15. -0 ** (-odd integer) is -INF, raise divbyzero
 *      16. +INF ** (+anything except 0,NAN) is +INF
 *      17. +INF ** (-anything except 0,NAN) is +0
 *      18. -INF ** (+odd integer) is -INF
 *      19. -INF ** (anything) = -0 ** (-anything), (anything except odd integer)
 *      20. (anything) ** 1 is (anything)
 *      21. (anything) ** -1 is 1/(anything)
 *      22. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
 *      23. (-anything except 0 and inf) ** (non-integer) is NAN
 *
 * Accuracy:
 *      pow(x,y) returns x**y nearly rounded. In particular
 *                      pow(integer,integer)
 *      always returns the correct integer provided it is
 *      representable.
 *
 * Constants :
 * The hexadecimal values are the intended ones for the following
 * constants. The decimal values may be used, provided that the
 * compiler will convert from decimal to binary accurately enough
 * to produce the hexadecimal values shown.
 */

/* 0x3FE2B803, 0x40000000 */

/* 0x3E4CFDEB, 0x43CFD006 */

/* 0x43400000, 0x00000000 */

/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */

/* 0x3FE33333, 0x33333303 */

/* 0x3FDB6DB6, 0xDB6FABFF */

/* 0x3FD55555, 0x518F264D */

/* 0x3FD17460, 0xA91D4101 */

/* 0x3FCD864A, 0x93C9DB65 */

/* 0x3FCA7E28, 0x4A454EEF */

/* 0x3FC55555, 0x5555553E */

/* 0xBF66C16C, 0x16BEBD93 */

/* 0x3F11566A, 0xAF25DE2C */

/* 0xBEBBBD41, 0xC5D26BF1 */

/* 0x3E663769, 0x72BEA4D0 */

/* 0x3FE62E42, 0xFEFA39EF */

/* 0x3FE62E43, 0x00000000 */

/* 0xBE205C61, 0x0CA86C39 */

/* -(1024-log2(ovfl+.5ulp)) */

/* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */

/* 0x3FEEC709, 0xE0000000 =(float)cp */

/* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/

/* 0x3FF71547, 0x652B82FE =1/ln2 */

/* 0x3FF71547, 0x60000000 =24b 1/ln2*/

/* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/

/* x**0 = 1, even if x is NaN */

/* 1**y = 1, even if y is NaN */

/* NaN if either arg is NaN */

/* determine if y is an odd int when x < 0
	 * yisint = 0       ... y is not an integer
	 * yisint = 1       ... y is an odd int
	 * yisint = 2       ... y is an even int
	 */

/* even integer y */

/* exponent */

/* special value of y */

/* y is +-inf */

/* (-1)**+-inf is 1 */

/* (|x|>1)**+-inf = inf,0 */

/* (|x|<1)**+-inf = 0,inf */

/* y is +-1 */

/* y is 2 */

/* y is 0.5 */

/* x >= +0 */

/* special value of x */

/* x is +-0,+-inf,+-1 */

/* z = (1/|x|) */

/* (-1)**non-int is NaN */

/* (x<0)**odd = -(|x|**odd) */

/* sign of result */

/* (x<0)**(non-int) is NaN */

/* (x<0)**(odd int) */

/* |y| is huge */

/* if |y| > 2**31 */

/* if |y| > 2**64, must o/uflow */

/* over/underflow if x is not close to one */

/* now |1-x| is tiny <= 2**-20, suffice to compute
		   log(x) by x-x^2/2+x^3/3-x^4/4 */

/* t has 20 trailing zeros */

/* ivln2_h has 21 sig. bits */

/* take care subnormal number */

/* determine interval */

/* normalize ix */

/* |x|<sqrt(3/2) */

/* |x|<sqrt(3)   */

/* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */

/* bp[0]=1.0, bp[1]=1.5 */

/* t_h=ax+bp[k] High */

/* compute log(ax) */

/* u+v = ss*(1+...) */

/* 2/(3log2)*(ss+...) */

/* cp_h+cp_l = 2/(3*log2) */

/* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */

/* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */

/* z >= 1024 */

/* if z > 1024 */

/* overflow */

/* overflow */

/* z <= -1075 */

// FIXME: instead of abs(j) use unsigned j

/* z < -1075 */

/* underflow */

/* underflow */

/*
	 * compute 2**(p_h+p_l)
	 */

/* if |z| > 0.5, set n = [z+0.5] */

/* new k for n */

/* subnormal output */


=== system/lib/libc/musl/src/math/powf.c ===
SHA256: 74069b3a380cf954361e0243b38de2094ae680e2ecfb3e50af61ab576f13babf
Primary Git blob: de8fab545545b4f2800cdb468fe99a07efea5487
/*
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */

/*
POWF_LOG2_POLY_ORDER = 5
EXP2F_TABLE_BITS = 5

ULP error: 0.82 (~ 0.5 + relerr*2^24)
relerr: 1.27 * 2^-26 (Relative error ~= 128*Ln2*relerr_log2 + relerr_exp2)
relerr_log2: 1.83 * 2^-33 (Relative error of logx.)
relerr_exp2: 1.69 * 2^-34 (Relative error of exp2(ylogx).)
*/

/* Subnormal input is normalized so ix has negative biased exponent.
   Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set.  */

/* x = 2^k z; where z is in range [OFF,2*OFF] and exact.
	   The range is split into N subintervals.
	   The ith subinterval contains z and c is near its center.  */

/* arithmetic shift */

/* log2(x) = log1p(z/c-1)/ln2 + log2(c) + k */

/* Pipelined polynomial evaluation to approximate log1p(r)/ln2.  */

/* The output of log2 and thus the input of exp2 is either scaled by N
   (in case of fast toint intrinsics) or not.  The unscaled xd must be
   in [-1021,1023], sign_bias sets the sign of the result.  */

/* N*x = k + r with r in [-1/2, 1/2] */

/* k */

/* x = k/N + r with r in [-1/(2N), 1/(2N)] */

/* k/N */

/* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */

/* Returns 0 if not int, 1 if odd int, 2 if even int.  The argument is
   the bit representation of a non-zero finite floating-point value.  */

/* Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan).  */

/* |x|<1 && y==inf or |x|>1 && y==-inf.  */

/* Without the barrier some versions of clang hoist the 1/x2 and
			   thus division by zero exception can be signaled spuriously.  */

/* x and y are non-zero finite.  */

/* Finite x < 0.  */

/* Normalize subnormal x so exponent becomes negative.  */

/* cannot overflow, y is single prec.  */

/* |y*log(x)| >= 126.  */


=== system/lib/libc/musl/src/math/powf_data.c ===
SHA256: 136f491b0f904842b926784134d0adba7a9103d2ce8a226276dd6e9260457398
Primary Git blob: 13e1d9a06a9eb0fb98be42da1a4bc042c5abc444
/*
 * Data definition for powf.
 *
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


=== system/lib/libc/musl/src/math/powf_data.h ===
SHA256: 5d632276e5f21cdcd47f35c53cf792640ad347aabce1e1bd5774fad5371fc8d8
Primary Git blob: 5b136e28374fb39b6acbab463ea92a844f09a749
/*
 * Copyright (c) 2017-2018, Arm Limited.
 * SPDX-License-Identifier: MIT
 */


=== system/lib/libc/musl/src/math/powl.c ===
SHA256: b1c9f5993fe37ce04e4291cdeaa8d690587f25076525a417c9657f082b7ae987
Primary Git blob: 6f64ea71182d8334fe0f41cc9886dbe70845804e
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_powl.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*                                                      powl.c
 *
 *      Power function, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, z, powl();
 *
 * z = powl( x, y );
 *
 *
 * DESCRIPTION:
 *
 * Computes x raised to the yth power.  Analytically,
 *
 *      x**y  =  exp( y log(x) ).
 *
 * Following Cody and Waite, this program uses a lookup table
 * of 2**-i/32 and pseudo extended precision arithmetic to
 * obtain several extra bits of accuracy in both the logarithm
 * and the exponential.
 *
 *
 * ACCURACY:
 *
 * The relative error of pow(x,y) can be estimated
 * by   y dl ln(2),   where dl is the absolute error of
 * the internally computed base 2 logarithm.  At the ends
 * of the approximation interval the logarithm equal 1/32
 * and its relative error is about 1 lsb = 1.1e-19.  Hence
 * the predicted relative error in the result is 2.3e-21 y .
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *
 *    IEEE     +-1000       40000      2.8e-18      3.7e-19
 * .001 < x < 1000, with log(x) uniformly distributed.
 * -1000 < y < 1000, y uniformly distributed.
 *
 *    IEEE     0,8700       60000      6.5e-18      1.0e-18
 * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed.
 *
 *
 * ERROR MESSAGES:
 *
 *   message         condition      value returned
 * pow overflow     x**y > MAXNUM      INFINITY
 * pow underflow   x**y < 1/MAXNUM       0.0
 * pow domain      x<0 and y noninteger  0.0
 *
 */

/* Table size */

/* log(1+x) =  x - .5x^2 + x^3 *  P(z)/Q(z)
 * on the domain  2^(-1/32) - 1  <=  x  <=  2^(1/32) - 1
 */

/* 1.0000000000000000000000E0L,*/

/* A[i] = 2^(-i/32), rounded to IEEE long double precision.
 * If i is even, A[i] + B[i/2] gives additional accuracy.
 */

/* 2^x = 1 + x P(x),
 * on the interval -1/32 <= x <= 0
 */

/* The following if denormal numbers are supported, else -MEXP: */

/* log2(e) - 1 */

/* XXX Prevent gcc from erroneously constant folding this. */

/* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */

/* make sure no invalid exception is raised by nan comparision */

/* 1**y = 1, even if y is nan */

/* x**0 = 1, even if x is nan */

/* if y*log2(x) < log2(LDBL_TRUE_MIN)-1 then x^y uflows to 0
	   if y*log2(x) > -log2(LDBL_TRUE_MIN)+1 > LDBL_MAX_EXP then x^y oflows
	   if |x|!=1 then |log2(x)| > |log(x)| > LDBL_EPSILON/2 so
	   x^y oflows/uflows if |y|*LDBL_EPSILON/2 > -log2(LDBL_TRUE_MIN)+1 */

/* y is not an odd int */

/* Set iyflg to 1 if y is an integer. */

/* Test for odd integer y. */

/* (x<0)**(odd int) */

/* (-0.0)**(-odd int) = -inf, divbyzero */

/* (+-0.0)**(negative) = inf, divbyzero */

/* (x<0)**(non-int) is NaN */

/* (x<0)**(integer) */

/* negate result */

/* (+integer)**(integer)  */

/* separate significand from exponent */

/* find significand in antilog table A[] */

/* Find (x - A[i])/A[i]
	 * in order to compute log(x/A[i]):
	 *
	 * log(x) = log( a x/a ) = log(a) + log(x/a)
	 *
	 * log(x/a) = log(1+v),  v = x/a - 1 = (x-a)/a
	 */

/* rational approximation for log(1+v):
	 *
	 * log(1+v)  =  v  -  v**2/2  +  v**3 P(v) / Q(v)
	 */

/* Convert to base 2 logarithm:
	 * multiply by log2(e) = 1 + LOG2EA
	 */

/* Compute exponent term of the base 2 logarithm. */

/* Now base 2 log of x is w + z. */

/* Multiply base 2 log by y, in extended precision. */

/* separate y into large part ya
	 * and small part yb less than 1/NXT
	 */

/* (w+z)(ya+yb)
	 * = w*ya + w*yb + z*y
	 */

/* Test the power of 2 for overflow */

/* overflow */

/* underflow */

/*0.0625L;*/

/* Now the product y * log2(x)  =  Hb + e/NXT.
	 *
	 * Compute base 2 exponential of Hb,
	 * where -0.0625 <= Hb <= 0.
	 */

/*  z = 2**Hb - 1  */

/* Express e/NXT as an integer plus a negative number of (1/NXT)ths.
	 * Find lookup table entry for the fractional power of 2.
	 */

/*  2**-e * ( 1 + (2**Hb-1) )  */

/* multiply by integer power of 2 */

/* Find a multiple of 1/NXT that is within 1/NXT of x. */

/*
 *      Positive real raised to integer power, long double precision
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, powil();
 * int n;
 *
 * y = powil( x, n );
 *
 *
 * DESCRIPTION:
 *
 * Returns argument x>0 raised to the nth power.
 * The routine efficiently decomposes n as a sum of powers of
 * two. The desired power is a product of two-to-the-kth
 * powers of x.  Thus to compute the 32767 power of x requires
 * 28 multiplications instead of 32767 multiplications.
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   x domain   n domain  # trials      peak         rms
 *    IEEE     .001,1000  -1022,1023  50000       4.3e-17     7.8e-18
 *    IEEE        1,2     -1022,1023  20000       3.9e-17     7.6e-18
 *    IEEE     .99,1.01     0,8700    10000       3.6e-16     7.2e-17
 *
 * Returns MAXNUM on overflow, zero on underflow.
 */

/* Overflow detection */

/* Calculate approximate logarithm of answer */

/* overflow */

/* underflow */

/* Handle tiny denormal answer, but with less accuracy
	 * since roundoff error in 1.0/x will be amplified.
	 * The precise demarcation should be the gradual underflow threshold.
	 */

/* First bit of the power */

/* arg to the 2-to-the-kth power */

/* if that bit is set, then include in product */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/remquo.c ===
SHA256: 7ccf8f5c1376de85a8741dcbdcd9feb69fe8268ddd49aebc796036f80a9eaee9
Primary Git blob: 59d5ad57e54dfc8399b3994c88faf3dc15b8c0d0
/* normalize x and y */

/* x mod y */

/* scale result and decide between |x| and |x|-|y| */


=== system/lib/libc/musl/src/math/remquof.c ===
SHA256: f40401d2bc1732932375a64590a6844229d566c1a6907a6aa6480a455284fcf9
Primary Git blob: 2f41ff706dde3e300aa0e8fbb5f7a868092f9615
/* normalize x and y */

/* x mod y */

/* scale result and decide between |x| and |x|-|y| */


=== system/lib/libc/musl/src/math/remquol.c ===
SHA256: ce2ab067c4780ef11482b40c6e93d0ce27b5c5df4fdb117716243b533ee1a829
Primary Git blob: 9b065c007f56e573a9d2dbb5a91fadd919cf290c
/* normalize x and y */

/* x mod y */

/* scale result and decide between |x| and |x|-|y| */


=== system/lib/libc/musl/src/math/rint.c ===
SHA256: 7b4b8a64b5fd2c73ebad944319471d427bbd0af826ebb48df157d1fe85840bb3
Primary Git blob: bd4c32f9f6d77e13fcbf2b894acf390318b164a1
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/rintf.c ===
SHA256: f47eb2fefe54508b46ad554437ebf9ad09de0a78cd140ccb42b4f0bf5a817f7c
Primary Git blob: 59401f2bf75cbfc8e0c63e0ce0edb16636e81265
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/round.c ===
SHA256: 2349e599e99052603794087193725d28180b5d3466d43d6e6e1b254627bf37ae
Primary Git blob: 130d58d2571e77cc15a67b355010e11c5ebebe91
/* raise inexact if x!=0 */


=== system/lib/libc/musl/src/math/scalb.c ===
SHA256: 7f7eda8fd9d537105136d56661d70788f912b9584bb116dea185db340c78ada5
Primary Git blob: efe69e60cd6f5c2cd3ba061dc43d141281d3c111
/* origin: FreeBSD /usr/src/lib/msun/src/e_scalb.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/*
 * scalb(x, fn) is provide for
 * passing various standard test suite. One
 * should use scalbn() instead.
 */


=== system/lib/libc/musl/src/math/scalbf.c ===
SHA256: b4a0485f7a11d994960c31947f0132c45afd47f599abbae4a9f2041f7f346a3f
Primary Git blob: f44ed5b64a0ff12c4fb9e1f272b4c8ba8189f03a
/* origin: FreeBSD /usr/src/lib/msun/src/e_scalbf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */


=== system/lib/libc/musl/src/math/scalbn.c ===
SHA256: a2e766283ed30c2b30c71e01dbdabef58faf92cc9aa84a01c1ce1069b6625696
Primary Git blob: 182f561068fda7bc8321dfc7991df8b6d58e1b56
/* make sure final n < -53 to avoid double
		   rounding in the subnormal range */


=== system/lib/libc/musl/src/math/sin.c ===
SHA256: 24e53a9d85f196f66919cc19247be5480bb607ef38844b1a24bc47c4fe4974ef
Primary Git blob: 055e215bc866d62936992058b7019b374cbcac7c
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* sin(x)
 * Return sine function of x.
 *
 * kernel function:
 *      __sin            ... sine function on [-pi/4,pi/4]
 *      __cos            ... cose function on [-pi/4,pi/4]
 *      __rem_pio2       ... argument reduction routine
 *
 * Method.
 *      Let S,C and T denote the sin, cos and tan respectively on
 *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
 *      in [-pi/4 , +pi/4], and let n = k mod 4.
 *      We have
 *
 *          n        sin(x)      cos(x)        tan(x)
 *     ----------------------------------------------------------
 *          0          S           C             T
 *          1          C          -S            -1/T
 *          2         -S          -C             T
 *          3         -C           S            -1/T
 *     ----------------------------------------------------------
 *
 * Special cases:
 *      Let trig be any of sin, cos, or tan.
 *      trig(+-INF)  is NaN, with signals;
 *      trig(NaN)    is that NaN;
 *
 * Accuracy:
 *      TRIG(x) returns trig(x) nearly rounded
 */

/* High word of x. */

/* |x| ~< pi/4 */

/* |x| < 2**-26 */

/* raise inexact if x != 0 and underflow if subnormal*/

/* sin(Inf or NaN) is NaN */

/* argument reduction needed */


=== system/lib/libc/musl/src/math/sincos.c ===
SHA256: 2b88cfba380b8d5aa8f8f6b9f055aee91fe112de9f967a4484807afcb5405d9d
Primary Git blob: 35b2d923968f1b5deaaf7e4183c288c2d2a05043
/* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* |x| ~< pi/4 */

/* if |x| < 2**-27 * sqrt(2) */

/* raise inexact if x!=0 and underflow if subnormal */

/* sincos(Inf or NaN) is NaN */

/* argument reduction needed */


=== system/lib/libc/musl/src/math/sincosf.c ===
SHA256: 0196bf2ccfa370be120b917f2379bb533950ea50818d329aeee076081690c95d
Primary Git blob: f8ca7232cfb371da2be6c3c87f079515fa4c01e1
/* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* Small multiples of pi/2 rounded to double precision. */

/* 0x3FF921FB, 0x54442D18 */

/* 0x400921FB, 0x54442D18 */

/* 0x4012D97C, 0x7F3321D2 */

/* 0x401921FB, 0x54442D18 */

/* |x| ~<= pi/4 */

/* |x| < 2**-12 */

/* raise inexact if x!=0 and underflow if subnormal */

/* |x| ~<= 5*pi/4 */

/* |x| ~<= 3pi/4 */

/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */

/* |x| ~<= 9*pi/4 */

/* |x| ~<= 7*pi/4 */

/* sin(Inf or NaN) is NaN */

/* general argument reduction needed */


=== system/lib/libc/musl/src/math/sincosl.c ===
SHA256: b3ca83d96032345e03afc67592ea503fd8de691b760d6786b7f55f30c87903d4
Primary Git blob: d3ac1c4c8c29e11067d55a3a99fa82eb888c5dd5
/* raise underflow if subnormal */

/* raise inexact if x!=0 */


=== system/lib/libc/musl/src/math/sinf.c ===
SHA256: 2583af55446f07da3225186c368a7aae5a0a0a0edab268967f4122b92e222b87
Primary Git blob: 64e39f50177ca1f3330a6dffa687c7f78841b975
/* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* Small multiples of pi/2 rounded to double precision. */

/* 0x3FF921FB, 0x54442D18 */

/* 0x400921FB, 0x54442D18 */

/* 0x4012D97C, 0x7F3321D2 */

/* 0x401921FB, 0x54442D18 */

/* |x| ~<= pi/4 */

/* |x| < 2**-12 */

/* raise inexact if x!=0 and underflow if subnormal */

/* |x| ~<= 5*pi/4 */

/* |x| ~<= 3pi/4 */

/* |x| ~<= 9*pi/4 */

/* |x| ~<= 7*pi/4 */

/* sin(Inf or NaN) is NaN */

/* general argument reduction needed */


=== system/lib/libc/musl/src/math/sinh.c ===
SHA256: ab082814c4b1bbad8ea7dcfde1e36167cd72be5ef0e8b3ef3def0e052dd74261
Primary Git blob: a01951ae6fc4fdb4954de0b6f24323b230f6ae88
/* sinh(x) = (exp(x) - 1/exp(x))/2
 *         = (exp(x)-1 + (exp(x)-1)/exp(x))/2
 *         = x + x^3/6 + o(x^5)
 */

/* |x| */

/* |x| < log(DBL_MAX) */

/* note: inexact and underflow are raised by expm1 */

/* note: this branch avoids spurious underflow */

/* note: |x|>log(0x1p26)+eps could be just h*exp(x) */

/* |x| > log(DBL_MAX) or nan */

/* note: the result is stored to handle overflow */


=== system/lib/libc/musl/src/math/sinhf.c ===
SHA256: 2c52f2c26163f8b7a0048465343510a5856d9c8cc954931722e121040fe81024
Primary Git blob: b9caa793c4f927e10dff4d0237c78fe677c54f58
/* |x| */

/* |x| < log(FLT_MAX) */

/* |x| > logf(FLT_MAX) or nan */


=== system/lib/libc/musl/src/math/sinhl.c ===
SHA256: b831736fbbd0c4669c1b11c66ecfcca2f9857fdf464455aebecf87819bd8aa9e
Primary Git blob: b305d4d2f3e9c5965bdbf4ddb445adef0168fd85
/* |x| */

/* |x| < log(LDBL_MAX) */

/* |x| > log(LDBL_MAX) or nan */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/sinl.c ===
SHA256: ef6c9704017e2af353a27fd1e57db1864704fb9f9e92badc2753c1c2961b2424
Primary Git blob: 9c0b16eed3492f1e843b9425f11b4ba57c980c7f
/* raise inexact if x!=0 and underflow if subnormal */


=== system/lib/libc/musl/src/math/sqrt.c ===
SHA256: 320a4405c11e39024193c279f41d7c43d892a58ece2e0917343f40cd977279e0
Primary Git blob: 6854c98381642d9ff0dd21a64261a0a970d1a339
/* returns a*b*2^-32 - e, with error 0 <= e < 1.  */

/* returns a*b*2^-64 - e, with error 0 <= e < 3.  */

// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236

/* special case handling.  */

/* x < 0x1p-1022 or inf or nan.  */

/* x is subnormal, normalize it.  */

/* argument reduction:
	   x = 4^e m; with integer e, and m in [1, 4)
	   m: fixed point representation [2.62]
	   2^e is the exponent part of the result.  */

/* approximate r ~ 1/sqrt(m) and s ~ sqrt(m) when m in [1,4)

	   initial estimate:
	   7bit table lookup (1bit exponent and 6bit significand).

	   iterative approximation:
	   using 2 goldschmidt iterations with 32bit int arithmetics
	   and a final iteration with 64bit int arithmetics.

	   details:

	   the relative error (e = r0 sqrt(m)-1) of a linear estimate
	   (r0 = a m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best,
	   a table lookup is faster and needs one less iteration
	   6 bit lookup table (128b) gives |e| < 0x1.f9p-8
	   7 bit lookup table (256b) gives |e| < 0x1.fdp-9
	   for single and double prec 6bit is enough but for quad
	   prec 7bit is needed (or modified iterations). to avoid
	   one more iteration >=13bit table would be needed (16k).

	   a newton-raphson iteration for r is
	     w = r*r
	     u = 3 - m*w
	     r = r*u/2
	   can use a goldschmidt iteration for s at the end or
	     s = m*r

	   first goldschmidt iteration is
	     s = m*r
	     u = 3 - s*r
	     r = r*u/2
	     s = s*u/2
	   next goldschmidt iteration is
	     u = 3 - s*r
	     r = r*u/2
	     s = s*u/2
	   and at the end r is not computed only s.

	   they use the same amount of operations and converge at the
	   same quadratic rate, i.e. if
	     r1 sqrt(m) - 1 = e, then
	     r2 sqrt(m) - 1 = -3/2 e^2 - 1/2 e^3
	   the advantage of goldschmidt is that the mul for s and r
	   are independent (computed in parallel), however it is not
	   "self synchronizing": it only uses the input m in the
	   first iteration so rounding errors accumulate. at the end
	   or when switching to larger precision arithmetics rounding
	   errors dominate so the first iteration should be used.

	   the fixed point representations are
	     m: 2.30 r: 0.32, s: 2.30, d: 2.30, u: 2.30, three: 2.30
	   and after switching to 64 bit
	     m: 2.62 r: 0.64, s: 2.62, d: 2.62, u: 2.62, three: 2.62  */

/* |r sqrt(m) - 1| < 0x1.fdp-9 */

/* |s/sqrt(m) - 1| < 0x1.fdp-9 */

/* |r sqrt(m) - 1| < 0x1.7bp-16 */

/* |s/sqrt(m) - 1| < 0x1.7bp-16 */

/* |r sqrt(m) - 1| < 0x1.3704p-29 (measured worst-case) */

/* repr: 3.61 */

/* -0x1p-57 < s - sqrt(m) < 0x1.8001p-61 */

/* repr: 12.52 */

/* -0x1.09p-52 < s - sqrt(m) < -0x1.fffcp-63 */

/* s < sqrt(m) < s + 0x1.09p-52,
	   compute nearest rounded result:
	   the nearest result to 52 bits is either s or s+0x1p-52,
	   we can decide by comparing (2^52 s + 0.5)^2 to 2^104 m.  */

/* handle rounding modes and inexact exception:
		   only (s+1)^2 == 2^42 m case is exact otherwise
		   add a tiny value to cause the fenv effects.  */


=== system/lib/libc/musl/src/math/sqrt_data.h ===
SHA256: 5fa47a8b8c1afbee4dcd10f71d2f6c433a24f9aa5ce7a90924cd1db236cbc03c
Primary Git blob: 260c7f9c292beb48fd7a0985a58a7740d38c0d5e
/* if x in [1,2): i = (int)(64*x);
   if x in [2,4): i = (int)(32*x-64);
   __rsqrt_tab[i]*2^-16 is estimating 1/sqrt(x) with small relative error:
   |__rsqrt_tab[i]*0x1p-16*sqrt(x) - 1| < -0x1.fdp-9 < 2^-8 */


=== system/lib/libc/musl/src/math/sqrtf.c ===
SHA256: 76e660944d71691d1eedd83dc59341dceb70d903094cd2832db3a446c34bd035
Primary Git blob: fd747026912155071f8c84592a5b63bbb1a38de7
/* see sqrt.c for more detailed comments.  */

// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236

/* x < 0x1p-126 or inf or nan.  */

/* x is subnormal, normalize it.  */

/* x = 4^e m; with int e and m in [1, 4).  */

/* 2^e is the exponent part of the return value.  */

/* compute r ~ 1/sqrt(m), s ~ sqrt(m) with 2 goldschmidt iterations.  */

/* |r*sqrt(m) - 1| < 0x1p-8 */

/* |s/sqrt(m) - 1| < 0x1p-8 */

/* |r*sqrt(m) - 1| < 0x1.7bp-16 */

/* |s/sqrt(m) - 1| < 0x1.7bp-16 */

/* -0x1.03p-28 < s/sqrt(m) - 1 < 0x1.fp-31 */

/* s < sqrt(m) < s + 0x1.08p-23 */

/* compute nearest rounded result.  */

/* handle rounding and inexact exception. */


=== system/lib/libc/musl/src/math/sqrtl.c ===
SHA256: 68480ff80f15fbfbfa1e8cec6d27e99c897762dc95760f6f97087fca33a95dc7
Primary Git blob: 81e68fea20c391b5584b22218883d0b5767a22be
/* top: 16 bit sign+exponent, x: significand.  */

/* force the top bit on non-zero (and non-subnormal) results.  */

/* return: top 16 bit is sign+exp and following bits are the significand.  */

/* ignore the top bit: pseudo numbers are not handled. */

/* returns a*b*2^-32 - e, with error 0 <= e < 1.  */

/* returns a*b*2^-64 - e, with error 0 <= e < 3.  */

/* a<<n, 0 <= n <= 127 */

/* a>>n, 0 <= n <= 127 */

/* returns a*b exactly.  */

/* returns a*b*2^-128 - e, with error 0 <= e < 7.  */

/* returns a*b % 2^128.  */

/* see sqrt.c for detailed comments.  */

// https://github.com/emscripten-core/emscripten/issues/15655

/* x < 0x1p-16382 or inf or nan.  */

/* x is subnormal, normalize it.  */

/* x = 4^e m; with int e and m in [1, 4) */

/* r ~ 1/sqrt(m) */

/* |r sqrt(m) - 1| < 0x1p-8 */

/* |r sqrt(m) - 1| < 0x1.7bp-16, switch to 64bit */

/* |r sqrt(m) - 1| < 0x1.a5p-31 */

/* |r sqrt(m) - 1| < 0x1.c001p-59, switch to 128bit */

/* repr: 3.125 */

/* -0x1p-116 < s - sqrt(m) < 0x3.8001p-125 */

/* s < sqrt(m) < s + 1 ULP + tiny */

/* handle rounding modes and inexact exception.  */


=== system/lib/libc/musl/src/math/tan.c ===
SHA256: 422d411bac962a1077ae394d14e54313012a6faa3476c20b2a66d3fb3f7a923f
Primary Git blob: 9c724a45af51e09f9da9069ba7ab1073e8fee05c
/* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* tan(x)
 * Return tangent function of x.
 *
 * kernel function:
 *      __tan           ... tangent function on [-pi/4,pi/4]
 *      __rem_pio2      ... argument reduction routine
 *
 * Method.
 *      Let S,C and T denote the sin, cos and tan respectively on
 *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
 *      in [-pi/4 , +pi/4], and let n = k mod 4.
 *      We have
 *
 *          n        sin(x)      cos(x)        tan(x)
 *     ----------------------------------------------------------
 *          0          S           C             T
 *          1          C          -S            -1/T
 *          2         -S          -C             T
 *          3         -C           S            -1/T
 *     ----------------------------------------------------------
 *
 * Special cases:
 *      Let trig be any of sin, cos, or tan.
 *      trig(+-INF)  is NaN, with signals;
 *      trig(NaN)    is that NaN;
 *
 * Accuracy:
 *      TRIG(x) returns trig(x) nearly rounded
 */

/* |x| ~< pi/4 */

/* |x| < 2**-27 */

/* raise inexact if x!=0 and underflow if subnormal */

/* tan(Inf or NaN) is NaN */

/* argument reduction */


=== system/lib/libc/musl/src/math/tanf.c ===
SHA256: 38b39aaf03d33341e606b67b3743ee5fa436b7e8338af155994d4b794b366003
Primary Git blob: aba197777d3aeb0dfb5621f92ade9f0e7615223c
/* origin: FreeBSD /usr/src/lib/msun/src/s_tanf.c */

/*
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
 * Optimized by Bruce D. Evans.
 */

/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */

/* Small multiples of pi/2 rounded to double precision. */

/* 0x3FF921FB, 0x54442D18 */

/* 0x400921FB, 0x54442D18 */

/* 0x4012D97C, 0x7F3321D2 */

/* 0x401921FB, 0x54442D18 */

/* |x| ~<= pi/4 */

/* |x| < 2**-12 */

/* raise inexact if x!=0 and underflow if subnormal */

/* |x| ~<= 5*pi/4 */

/* |x| ~<= 3pi/4 */

/* |x| ~<= 9*pi/4 */

/* |x| ~<= 7*pi/4 */

/* tan(Inf or NaN) is NaN */

/* argument reduction */


=== system/lib/libc/musl/src/math/tanh.c ===
SHA256: 7e290e86729cba6ccc8eb1f7db2452736daf1a2a8ce01b210db5787fee5cb762
Primary Git blob: 20d6dbcf4175c7aad93fe70a53056f0d3e1c4f13
/* tanh(x) = (exp(x) - exp(-x))/(exp(x) + exp(-x))
 *         = (exp(2*x) - 1)/(exp(2*x) - 1 + 2)
 *         = (1 - exp(-2*x))/(exp(-2*x) - 1 + 2)
 */

/* x = |x| */

/* |x| > log(3)/2 ~= 0.5493 or nan */

/* |x| > 20 or nan */

/* note: this branch avoids raising overflow */

/* |x| > log(5/3)/2 ~= 0.2554 */

/* |x| >= 0x1p-1022, up to 2ulp error in [0.1,0.2554] */

/* |x| is subnormal */

/* note: the branch above would not raise underflow in [0x1p-1023,0x1p-1022) */


=== system/lib/libc/musl/src/math/tanhf.c ===
SHA256: 4787b2f6be28bb2ae9721d510b12d2b9aebf96a594f26f25a3dc267f029800df
Primary Git blob: 10636fbd7be6c21d1c58326eba2bf7179b0dea8f
/* x = |x| */

/* |x| > log(3)/2 ~= 0.5493 or nan */

/* |x| > 10 */

/* |x| > log(5/3)/2 ~= 0.2554 */

/* |x| >= 0x1p-126 */

/* |x| is subnormal */


=== system/lib/libc/musl/src/math/tanhl.c ===
SHA256: 459c4edb87e20d9d3abfdd5c9f1806cfa8fcf19f4e95759bca64da4969290355
Primary Git blob: 4e1aa9f87dde30bc14f43bed200fe2a968e45108
/* x = |x| */

/* |x| > log(3)/2 ~= 0.5493 or nan */

/* |x| >= 32 */

/* |x| > log(5/3)/2 ~= 0.2554 */

/* |x| is small */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/tanl.c ===
SHA256: aa2fa3676c4a8754982e5da9308aa9f14dfc268ef9f709e7ef7792d523d2c3a0
Primary Git blob: 6af067127ade990b98d26696594e5737fbf50ade
/* raise inexact if x!=0 and underflow if subnormal */


=== system/lib/libc/musl/src/math/tgamma.c ===
SHA256: 5dc226d9456bdd35754d7295f373d545e835f1509c1de7262ab0335da732b562
Primary Git blob: 28f6e0f8327a9368c0c39bc2db4b25033cb24895
/*
"A Precision Approximation of the Gamma Function" - Cornelius Lanczos (1964)
"Lanczos Implementation of the Gamma Function" - Paul Godfrey (2001)
"An Analysis of the Lanczos Gamma Approximation" - Glendon Ralph Pugh (2004)

approximation method:

                        (x - 0.5)         S(x)
Gamma(x) = (x + g - 0.5)         *  ----------------
                                    exp(x + g - 0.5)

with
                 a1      a2      a3            aN
S(x) ~= [ a0 + ----- + ----- + ----- + ... + ----- ]
               x + 1   x + 2   x + 3         x + N

with a0, a1, a2, a3,.. aN constants which depend on g.

for x < 0 the following reflection formula is used:

Gamma(x)*Gamma(-x) = -pi/(x sin(pi x))

most ideas and constants are from boost and python
*/

/* sin(pi x) with x > 0x1p-100, if sin(pi*x)==0 the sign is arbitrary */

/* argument reduction: x = |x| mod 2 */

/* spurious inexact when x is odd int */

/* reduce x into [-.25,.25] */

/* case 4 */

//static const double g = 6.024680040776729583740234375;

/* n! for small integer n */

/* S(x) rational function for positive x */

/* to avoid overflow handle large x differently */

/* special cases */

/* tgamma(nan)=nan, tgamma(inf)=inf, tgamma(-inf)=nan with invalid */

/* |x| < 2^-54: tgamma(x) ~ 1/x, +-0 raises div-by-zero */

/* integer arguments */

/* raise inexact when non-integer */

/* x >= 172: tgamma(x)=inf with overflow */

/* x =< -184: tgamma(x)=+-0 with underflow */

/* |x| >= 184 */

/* handle the error of x + g - 0.5 */

/* reflection formula for negative x */

/* sinpi(absx) is not 0, integers are already handled */

/* special cases */

/* lgamma(nan)=nan, lgamma(+-inf)=inf */

/* integer arguments */

/* n <= 0: lgamma(n)=inf with divbyzero */

/* n == 1,2: lgamma(n)=0 */

/* lgamma(x) ~ -log(|x|) for tiny |x| */

/* use tgamma for smaller |x| */

/* second term (log(S)-g) could be more precise here.. */

/* or with stirling: (|x|-0.5)*(log(|x|)-1) + poly(1/|x|) */

/* reflection formula for negative x */


=== system/lib/libc/musl/src/math/tgammal.c ===
SHA256: b9f00584454232f6d4c6cf76b8198221a4cc047c92fa749e5f41476c9b54579f
Primary Git blob: 5336c5b194e86c57797562191ad39cd4af7fafe4
/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_tgammal.c */

/*
 * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 *      Gamma function
 *
 *
 * SYNOPSIS:
 *
 * long double x, y, tgammal();
 *
 * y = tgammal( x );
 *
 *
 * DESCRIPTION:
 *
 * Returns gamma function of the argument.  The result is
 * correctly signed.
 *
 * Arguments |x| <= 13 are reduced by recurrence and the function
 * approximated by a rational function of degree 7/8 in the
 * interval (2,3).  Large arguments are handled by Stirling's
 * formula. Large negative arguments are made positive using
 * a reflection formula.
 *
 *
 * ACCURACY:
 *
 *                      Relative error:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE     -40,+40      10000       3.6e-19     7.9e-20
 *    IEEE    -1755,+1755   10000       4.8e-18     6.5e-19
 *
 * Accuracy for large arguments is dominated by error in powl().
 *
 */

/*
tgamma(x+2) = tgamma(x+2) P(x)/Q(x)
0 <= x <= 1
Relative error
n=7, d=8
Peak error =  1.83e-20
Relative error spread =  8.4e-23
*/

/*
static const long double P[] = {
-3.01525602666895735709e0L,
-3.25157411956062339893e1L,
-2.92929976820724030353e2L,
-1.70730828800510297666e3L,
-7.96667499622741999770e3L,
-2.59780216007146401957e4L,
-5.99650230220855581642e4L,
-7.15743521530849602425e4L
};
static const long double Q[] = {
 1.00000000000000000000e0L,
-1.67955233807178858919e1L,
 8.85946791747759881659e1L,
 5.69440799097468430177e1L,
-1.98526250512761318471e3L,
 3.31667508019495079814e3L,
 1.60577839621734713377e4L,
-2.97045081369399940529e4L,
-7.15743521530849602412e4L
};
*/

/*static const long double LOGPI = 1.14472988584940017414L;*/

/* Stirling's formula for the gamma function
tgamma(x) = sqrt(2 pi) x^(x-.5) exp(-x) (1 + 1/x P(1/x))
z(x) = x
13 <= x <= 1024
Relative error
n=8, d=0
Peak error =  9.44e-21
Relative error spread =  8.8e-4
*/

/* 1/tgamma(x) = z P(z)
 * z(x) = 1/x
 * 0 < x < 0.03125
 * Peak relative error 4.2e-23
 */

/* 1/tgamma(-x) = z P(z)
 * z(x) = 1/x
 * 0 < x < 0.03125
 * Peak relative error 5.16e-23
 * Relative error spread =  2.5e-24
 */

/* Gamma function computed by Stirling's formula.
 */

/* For large x, use rational coefficients from the analytical expansion.  */

/* Avoid overflow in pow() */

/* z==1 if x was originally +-0 */

// TODO: broken implementation to make things compile


=== system/lib/libc/musl/src/math/trunc.c ===
SHA256: be4707056296c0d92a692093cc8ec85da0a2c76052ffacff5ca8817642a6179f
Primary Git blob: c6d25ec1b456e01b3d9deb33f2dd534934ede784
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/truncf.c ===
SHA256: ae88b8ea3d0c3c18ba8701cb72d63b2cc7bcb0d9f9021184f1cadb3d13cf3c44
Primary Git blob: 3c9f7f46617369b00c6979bf9bdf0b7e497fbe01
// XXX EMSCRIPTEN: use the wasm instruction via clang builtin

// See https://github.com/emscripten-core/emscripten/issues/9236


=== system/lib/libc/musl/src/math/truncl.c ===
SHA256: e58a1a25cb4a1446bf087f681fd191cbf2ed6a69297b099e2a5d99691966ac80
Primary Git blob: f07b1934097bcbb932e37a8b0710c99738993e39
/* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */


=== system/lib/libc/musl/src/misc/fmtmsg.c ===
SHA256: 27354c57b1827561585a73dbe9f2d7f97cd73563d4043cf2907912c8faaebb6e
Primary Git blob: 69170b25429c4974fdcc90e44d941b497fd9eb6d
/* Public domain fmtmsg()
 * Written by Isaac Dunham, 2014
 */

/*
 * If lstr is the first part of bstr, check that the next char in bstr
 * is either \0 or :
 */

//ignore MSGVERB-unrecognized component


=== system/lib/libc/musl/src/misc/getopt.c ===
SHA256: 5454d18e0383f364ac2ab85ce44820c4224281e57c0abcc485040d53ac46f43f
Primary Git blob: b08abbc96871b1c1a5f99ab5108734460d1a32c7
/* XXX EMSCRIPTEN: Use macro version here */

/* replacement char */


=== system/lib/libc/musl/src/misc/ioctl.c ===
SHA256: 15ecc4666b766b7ef4e5042864aea860f6c6f94736430c39548e9fc1ea6cf4f1
Primary Git blob: 0dd521ad58dfe3a52a0242ee37295cae8a1c7901
// The upstream version below is UB in C2x and rejected by clang.

/* yields a type for a struct with original size n, with a misaligned
 * timeval/timespec expanded from 32- to 64-bit. for use with ioctl
 * number producing macros; only size of result is meaningful. */

/* SNDRV_TIMER_IOCTL_STATUS */

/* SNDRV_PCM_IOCTL_STATUS[_EXT] */

/* SNDRV_RAWMIDI_IOCTL_STATUS */

/* SNDRV_PCM_IOCTL_SYNC_PTR - with 3 subtables */

/* snd_pcm_sync_ptr (flags only) */

/* snd_pcm_mmap_status */

/* snd_pcm_mmap_control (each member) */

/* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */

/* VIDIOC_DQEVENT */

/* VIDIOC_OMAP3ISP_STAT_REQ */

/* PPPIOCGIDLE */

/* PPGETTIME, PPSETTIME */

/* LPSETTIMEOUT */

/* offsets hard-coded for SNDRV_PCM_IOCTL_SYNC_PTR;
		 * if another exception appears this needs changing. */

/* snd_pcm_mmap_control, special-cased due to kernel
		 * type definition having been botched. */


=== system/lib/libc/musl/src/misc/openpty.c ===
SHA256: 31d2740a5fb8e5239ad345a971f4b9dd12e041d89faee537d49e518bc650c4b2
Primary Git blob: c10740606111778c16b1d6c3dd3adb5a791240b6
/* Nonstandard, but vastly superior to the standard functions */


=== system/lib/libc/musl/src/misc/realpath.c ===
SHA256: 722f14030bf9e172b87becff580cc8e31a4f5b2dc568beb64f7ac47edec6650e
Primary Git blob: db8b74dc8dbbcce1b77885bcc446d603db22f284
/* Main loop. Each iteration pops the next part from stack of
	 * remaining path components and consumes any slashes that follow.
	 * If not a link, it's moved to output; if a link, contents are
	 * pushed to the stack. */

/* If stack starts with /, the whole component is / or //
		 * and the output state must be reset. */

/* Initial // is special. */

/* Skip any . component but preserve check_dir status. */

/* Copy next component onto output at least temporarily, to
		 * call readlink, but wait to advance output position until
		 * determining it's not a link. */

/* Any non-.. path components we could cancel start
			 * after nup repetitions of the 3-byte string "../";
			 * if there are none, accumulate .. components to
			 * later apply to cwd, if needed. */

/* When previous components are already known to be
			 * directories, processing .. can skip readlink. */

/* If link contents end in /, strip any slashes already on
		 * stack to avoid /->// or //->/// or spurious toolong. */

/* Skip the stack advancement in case we have a new
		 * absolute base path. */

/* Cancel any initial .. components. */


=== system/lib/libc/musl/src/mman/mmap.c ===
SHA256: 978ec97bb4a1985f1177a56444150cf7da0271be5ec88428ee111263ba59ef6e
Primary Git blob: c755ca849eff484b21b98781426b098a45e2258a
/* Fixup incorrect EPERM from kernel. */


=== system/lib/libc/musl/src/multibyte/internal.h ===
SHA256: e5ba77a0870b47c515e610827fe4a62842ec9c7a8e04edd6ece3498495e22a83
Primary Git blob: 45bbc6d06289747b728fb26e416de0156a6eed74
/* Upper 6 state bits are a negative integer offset to bound-check next byte */

/*    equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f      */

/* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */

/* Arbitrary encoding for representing code units instead of characters. */

/* Get inline definition of MB_CUR_MAX. */


=== system/lib/libc/musl/src/multibyte/mbrtoc16.c ===
SHA256: 6a4851fa5eba90ca8780856c457a23c1051a360dbd29c551ad443da2389df413
Primary Git blob: 765ff9037cd3554db14e275650adb7c807632777
/* mbrtowc states for partial UTF-8 characters have the high bit set;
	 * we use nonzero states without high bit for pending surrogates. */


=== system/lib/libc/musl/src/multibyte/mbsnrtowcs.c ===
SHA256: e4d2c443f55abc5eb73ce5317da115e46496689466cb23f62ab401cfd47d9501
Primary Git blob: 931192e2d83c4291059a9c6e18ee58d6fdf50592
/* making sure output buffer size is at most n/4 will ensure
	 * that mbsrtowcs never reads more than n input bytes. thus
	 * we can use mbsrtowcs as long as it's practical.. */

/* have to roll back partial character */

/* safe - this loop runs fewer than sizeof(wbuf)/8 times */


=== system/lib/libc/musl/src/multibyte/mbtowc.c ===
SHA256: ae0d9e5879735862a5c2cf65c32af8e6c4a4bb695bfcd269fef1cd3ab0be2656
Primary Git blob: c191bb038bbfdb05a81daf64c732de3b43b40424
/* Avoid excessive checks against n: If shifting the state n-1
	 * times does not clear the high bit, then the value of n is
	 * insufficient to read a character */


=== system/lib/libc/musl/src/network/dn_comp.c ===
SHA256: a3e0cb70d9963eca64c39881ca8cf2b31bda56f524cca984c52495329f237965
Primary Git blob: f0ccd160f657dc7b7b531a6c1d8d387042a557af
/* RFC 1035 message compression */

/* label start offsets of a compressed domain name s */

/* label lengths of an ascii domain name s */

/* longest suffix match of an ascii domain with a compressed domain name dn */

/* encode unmatched part */

/* add tail */

/* save dst pointer */


=== system/lib/libc/musl/src/network/dn_expand.c ===
SHA256: 65f33dceff184f13aa3f9a6d5617d1ef5c33ae144c8b0940c9a4265a51bac463
Primary Git blob: eac343af5ed4f8142985e214c4c531397678d0b1
/* detect reference loop using an iteration counter */

/* loop invariants: p<end, dest<dend */


=== system/lib/libc/musl/src/network/ether.c ===
SHA256: 31d1549189d1b1aebd88565ff9e7683e6074c4d6960f4a78f261d8e2ef0d0384
Primary Git blob: 4304a972fe5affea6cf5d24a1e802a9043e9fa83
/* bad format */

/* bad byte */

/* bad format */


=== system/lib/libc/musl/src/network/getifaddrs.c ===
SHA256: 1d69be9311220e95a26848c8f1b95b50de137716649b5b4099d37d13178dd76f
Primary Git blob: 74df4d6c6a211a600d5c2c2a0f674198c5f72e24
/* getifaddrs() reports hardware addresses with PF_PACKET that implies
 * struct sockaddr_ll.  But e.g. Infiniband socket address length is
 * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct
 * to extend ssl_addr - callers should be able to still use it. */

/* If ifa_addr is already set we, received an IFA_LOCAL before
				 * so treat this as destination address */

/* If ifa_addr is set and we get IFA_LOCAL, assume we have
				 * a point-to-point network. Move address to correct field. */


=== system/lib/libc/musl/src/network/getservbyname_r.c ===
SHA256: a8ca85d0815a18c5afc704a0168cd90573b0f6152b0713348ad2c20fe0ebbe1f
Primary Git blob: cad6317ab84243e5bc8de3a1d8ce17eb4a688a5e
/* Don't treat numeric port number strings as service records. */

/* Align buffer */


=== system/lib/libc/musl/src/network/getservbyport_r.c ===
SHA256: 22374d6cd75aaceda2bc8cdf3928932ea71a346cbe790ffe087063183454b6a9
Primary Git blob: e4cc3079c1d19784625adc84b378742ce1ced555
/* Align buffer */

/* A numeric port string is not a service record. */


=== system/lib/libc/musl/src/network/if_nameindex.c ===
SHA256: def37c8439d2e5563e01f0840f6948046f9546797472fdc89fca9ea6d3e0e875
Primary Git blob: 2deaef769600e5bb6b67d613eb3b3e1f65597383
/* suppress duplicates */


=== system/lib/libc/musl/src/network/inet_ntop.c ===
SHA256: f67c5afa4395699d32fe9f65e4d4fa7b94a7e5b63e7fcf08bb28b05234fab865
Primary Git blob: 4bfef2c557ab4478afeb5c22f5d548fd69e51d3c
/* Replace longest /(^0|:)[:0]{2,}/ with "::" */


=== system/lib/libc/musl/src/network/lookup.h ===
SHA256: b15429f00d8e71cf32fcd47264c5fcf7a41f94e58612d6fb9ddac29907bd67e8
Primary Git blob: 54b2f8b5bff1bdcd5290fdd5de9f4699a50ce0c4
/* The limit of 48 results is a non-sharp bound on the number of addresses
 * that can fit in one 512-byte DNS packet full of v4 results and a second
 * packet full of v6 results. Due to headers, the actual limit is lower. */


=== system/lib/libc/musl/src/network/lookup_ipliteral.c ===
SHA256: 1e18387d86995bb2e0e6f56f6fe22460db0c2c5be76f6bea95bc2aec3507d193
Primary Git blob: 1e76620656b262bcad3edb03ab5531046725d4a8
/* wrong family */

/* wrong family */


=== system/lib/libc/musl/src/network/lookup_serv.c ===
SHA256: 012d0861a067b8736a0162a2882b265ae6e411b7fee89adeb9bd5b9df264264e
Primary Git blob: ae3827785132736854c2d121b016d24bfec33a75
/* Find service name */

/* Skip past canonical name at beginning of line */


=== system/lib/libc/musl/src/network/netlink.h ===
SHA256: ed0daabbdfd03a0fd76faf6b7399e20b0bb18593bcd00f1ac1a0c577e8531de5
Primary Git blob: 873fabe2b80350f4a6feee782a626dbdd72b9613
/* linux/netlink.h */

/* linux/rtnetlink.h */

/* linux/if_link.h */

/* linux/if_addr.h */

/* musl */


=== system/lib/libc/musl/src/network/res_mkquery.c ===
SHA256: 182f2b4c11c04ab11e3783fce2d2b371b7b545c9c033f38601fdfe621c02c7cd
Primary Git blob: 614bf7864b489046442efd01d96fc3a0eba5adf4
/* Construct query template - ID will be filled later */

/* AD */

/* Make a reasonably unpredictable id */


=== system/lib/libc/musl/src/network/res_msend.c ===
SHA256: 2a757ca85d7d4805d2c81245f802c674dec343b9d40bd17f73e85c16394d33aa
Primary Git blob: 109942806c29e22048ebaf68968ed7a893e426ec
/* Adjust iovec in msghdr to skip first n bytes. */

/* Internal contract for __res_msend[_rc]: asize must be >=512, nqueries
 * must be sufficiently small to be safe as VLA size. In practice it's
 * either 1 or 2, anyway. */

/* Get local address and open/bind a socket */

/* Handle case where system lacks IPv6 support */

/* Convert any IPv4 addresses in a mixed environment to v4-mapped */

/* Past this point, there are no errors. Each individual query will
	 * yield either no reply (indicated by zero length) or an answer
	 * packet which is up to the caller to interpret. */

/* This is the loop exit condition: that all queries
		 * have an accepted answer. */

/* Query all configured namservers in parallel */

/* Wait for a response, or until time to retry */

/* Ignore non-identifiable packets */

/* Ignore replies from addresses we didn't send to */

/* Find which query this answer goes with, if any */

/* Only accept positive or negative responses;
			 * retry immediately on server failure, and ignore
			 * all other codes such as refusal. */

/* Store answer in the right slot, or update next
			 * available temp slot if it's already in place. */

/* Ignore further UDP if all slots full or TCP-mode */

/* If answer is truncated (TC bit), fallback to TCP */

/* Storing the length here commits the accepted answer.
			 * Immediately close TCP socket so as not to consume
			 * resources we no longer need. */

/* Disregard any incomplete TCP results */


=== system/lib/libc/musl/src/network/res_state.c ===
SHA256: c02d0851abea624ba8468bd793f8352563638624ba5d3a9a68525b0b7a908b43
Primary Git blob: 5c42cda5c35f098a70f26016407c602ecf645195
/* This is completely unused, and exists purely to satisfy broken apps. */


=== system/lib/libc/musl/src/network/resolvconf.c ===
SHA256: c0bed0bcab66b3e47a0190565d8fbf1211da125777749210c3e0155452655469
Primary Git blob: ceabf0808450b056708129b5b937e413884c5c8c
/* Ignore lines that get truncated rather than
			 * potentially misinterpreting them. */

/* This can never happen anyway with chosen buffer sizes. */


=== system/lib/libc/musl/src/network/sendmmsg.c ===
SHA256: 62e2ef4287895bf9474c6a23e2fbc40605d34616bd9e915f40c02f0406c51503
Primary Git blob: eeae1d0a5822503f5c572a46e3d3696f6c95b1b9
/* Can't use the syscall directly because the kernel has the wrong
	 * idea for the types of msg_iovlen, msg_controllen, and cmsg_len,
	 * and the cmsg blocks cannot be modified in-place. */

/* This matches the kernel. */

/* As an unfortunate inconsistency, the sendmmsg API uses
		 * unsigned int for the resulting msg_len, despite sendmsg
		 * returning ssize_t. However Linux limits the total bytes
		 * sent by sendmsg to INT_MAX, so the assignment is safe. */


=== system/lib/libc/musl/src/prng/random.c ===
SHA256: 3a47a757115e2a2ea7b1242a0000100ad802c27c2a398b4d8b8360d768780209
Primary Git blob: d3780fa7eac3b47fd15ce51a546a66d1a0ce93a3
/*
this code uses the same lagged fibonacci generator as the
original bsd random implementation except for the seeding
which was broken in the original
*/

/* make sure x contains at least one odd number */


=== system/lib/libc/musl/src/regex/fnmatch.c ===
SHA256: b6b0d4f973210b3c825100a3dd684a3147a588e7e61835919096b432334761fe
Primary Git blob: 978fff884239b27b2256ee28a7bdf3bec022c310
/*
 * An implementation of what I call the "Sea of Stars" algorithm for
 * POSIX fnmatch(). The basic idea is that we factor the pattern into
 * a head component (which we match first and can reject without ever
 * measuring the length of the string), an optional tail component
 * (which only exists if the pattern contains at least one star), and
 * an optional "sea of stars", a set of star-separated components
 * between the head and tail. After the head and tail matches have
 * been removed from the input string, the components in the "sea of
 * stars" are matched sequentially by searching for their first
 * occurrence past the end of the previous match.
 *
 * - Rich Felker, April 2012
 */

/* Compute real pat length if it was initially unknown/-1 */

/* Find the last * in pat and count chars needed after it */

/* Past this point we need not check for UNMATCHABLE in pat,
	 * because all of pat has already been parsed once. */

/* Compute real str length if it was initially unknown/-1 */

/* Find the final tailcnt chars of str, accounting for UTF-8.
	 * On illegal sequences we may get it wrong, but in that case
	 * we necessarily have a matching failure anyway. */

/* Check that the pat and str tails match */

/* We're all done with the tails now, so throw them out */

/* Match pattern components until there are none left */

/* Encountering * completes/commits a component */

/* If we failed, advance str, by 1 char if it's a valid
		 * char, or past all invalid bytes otherwise. */


=== system/lib/libc/musl/src/regex/glob.c ===
SHA256: ceb34d24986c6eb39b8ee4f85c5f942559bdb6e0dcd1bcf3e6cff0bc57815fe9
Primary Git blob: 87bae084fb27edde03e773fb7092dba9a796d597
/* If GLOB_MARK is unused, we don't care about type. */

/* Special-case the remaining pattern being all slashes, in
	 * which case we can use caller-passed type if it's a dir. */

/* Consume maximal [escaped-]literal prefix of pattern, copying
	 * and un-escaping it to the running buffer as we go. */

/* Backslashes inside a bracket are (at least by
			 * our interpretation) non-special, so if next
			 * char is ']' we have a complete expression. */

/* Unpaired final backslash never matches. */

/* Only store a character if it fits in the buffer, but if
		 * a potential bracket expression is open, the overflow
		 * must be remembered and handled later only if the bracket
		 * is unterminated (and thereby a literal), so as not to
		 * disallow long bracket expressions with short matches. */

/* If we consume any new components, the caller-passed type
		 * or dummy type from above is no longer valid. */

/* If we consumed any components above, or if GLOB_MARK is
		 * requested and we don't yet know if the match is a dir,
		 * we must confirm the file exists and/or determine its type.
		 *
		 * If marking dirs, symlink type is inconclusive; we need the
		 * type for the symlink target, and therefore must try stat
		 * first unless type is known not to be a symlink. Otherwise,
		 * or if that fails, use lstat for determining existence to
		 * avoid false negatives in the case of broken symlinks. */

/* Check if the '/' was escaped and, if so, remove the escape char
	 * so that it will not be unpaired when passed to fnmatch. */

/* Quickly skip non-directories when there's pattern left. */

/* With GLOB_PERIOD, don't allow matching . or .. unless
		 * fnmatch would match them with FNM_PERIOD rules in effect. */


=== system/lib/libc/musl/src/regex/regcomp.c ===
SHA256: 56b0a765e084a5cd3ed7113a893b50d259265ba76b6bea98889c45d7aec302a0
Primary Git blob: fb24556ebe12e33cd07d86a7953e2ce30f45c3b7
/*
  regcomp.c - TRE POSIX compatible regex compilation functions.

  Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

/***********************************************************************
 from tre-compile.h
***********************************************************************/

/***********************************************************************
 from tre-ast.c and tre-ast.h
***********************************************************************/

/* The different AST node types. */

/* Special subtypes of TRE_LITERAL. */

/* Empty leaf (denotes empty string). */

/* Assertion leaf. */

/* Tag leaf. */

/* Back reference leaf. */

/* A generic AST node.  All AST nodes consist of this node on the top
   level with `obj' pointing to the actual content. */

/* Type of the node. */

/* Pointer to actual node. */

/* A "literal" node.  These are created for assertions, back references,
   tags, matching parameter settings, and all expressions that match one
   character. */

/* A "catenation" node.	 These are created when two regexps are concatenated.
   If there are more than one subexpressions in sequence, the `left' part
   holds all but the last, and `right' part holds the last subexpression
   (catenation is left associative). */

/* An "iteration" node.	 These are created for the "*", "+", "?", and "{m,n}"
   operators. */

/* Subexpression to match. */

/* Minimum number of consecutive matches. */

/* Maximum number of consecutive matches. */

/* If 0, match as many characters as possible, if 1 match as few as
     possible.	Note that this does not always mean the same thing as
     matching as many/few repetitions as possible. */

/* An "union" node.  These are created for the "|" operator. */

/***********************************************************************
 from tre-stack.c and tre-stack.h
***********************************************************************/

/* Creates a new stack object.	`size' is initial size in bytes, `max_size'
   is maximum size, and `increment' specifies how much more space will be
   allocated with realloc() if all space gets used up.	Returns the stack
   object or NULL if out of memory. */

/* Frees the stack object. */

/* Returns the current number of objects in the stack. */

/* Each tre_stack_push_*(tre_stack_t *s, <type> value) function pushes
   `value' on top of stack `s'.  Returns REG_ESPACE if out of memory.
   This tries to realloc() more space before failing if maximum size
   has not yet been reached.  Returns REG_OK if successful. */

/* Each tre_stack_pop_*(tre_stack_t *s) function pops the topmost
   element off of stack `s' and returns it.  The stack must not be
   empty. */

/* Just to save some typing. */

/*CONSTCOND*/

/***********************************************************************
 from tre-parse.c and tre-parse.h
***********************************************************************/

/* Parse context. */

/* Memory allocator. The AST is allocated using this. */

/* Stack used for keeping track of regexp syntax. */

/* The parsed node after a parse function returns. */

/* Position in the regexp pattern after a parse function returns. */

/* The first character of the last subexpression parsed. */

/* Current submatch ID. */

/* Current position (number of literal). */

/* The highest back reference or -1 if none seen so far. */

/* Compilation flags. */

/* Some macros for expanding \w, \s, etc. */

/* Expands a macro delimited by `regex' and `regex_end' to `buf', which
   must have at least `len' items.  Sets buf[0] to zero if the there
   is no match in `tre_macros'. */

/* assumes the range of valid code_min is < INT_MAX */

/* assumes islower(c) and isupper(c) are exclusive
		   and toupper(c)!=c if islower(c).
		   multiple opposite case characters are not supported */

/* Maximum number of character classes in a negated bracket expression. */

// TODO: parse bracket into a set of non-overlapping [lo,hi] ranges

/*
bracket grammar:
Bracket  =  '[' List ']'  |  '[^' List ']'
List     =  Term  |  List Term
Term     =  Char  |  Range  |  Chclass  |  Eqclass
Range    =  Char '-' Char  |  Char '-' '-'
Char     =  Coll  |  coll_single
Meta     =  ']'  |  '-'
Coll     =  '[.' coll_single '.]'  |  '[.' coll_multi '.]'  |  '[.' Meta '.]'
Eqclass  =  '[=' coll_single '=]'  |  '[=' coll_multi '=]'
Chclass  =  '[:' class ':]'

coll_single is a single char collating element but it can be
 '-' only at the beginning or end of a List and
 ']' only at the beginning of a List and
 '^' anywhere except after the openning '['
*/

/* extension: [a-z--@] is accepted as [a-z]|[--@] */

/* collating symbols and equivalence classes are not supported */

/* XXX - Should use collation order instead of
				   encoding values in character ranges. */

/* Add opposite-case codepoints if REG_ICASE is present.
			   It seems that POSIX requires that bracket negation
			   should happen before case-folding, but most practical
			   implementations do it the other way around. Changing
			   the order would need efficient representation of
			   case-fold ranges and bracket range sets even with
			   simple patterns so this is ok for now. */

/*
		 * With REG_NEWLINE, POSIX requires that newlines are not matched by
		 * any form of a non-matching list.
		 */

/* Sort the array if we need to negate it. */

/* extra lit for the last negated range */

/* negated classes */

/* Build a union of the items in the array, negated if necessary. */

/* Overlap. */

/*
BRE grammar:
Regex  =  Branch  |  '^'  |  '$'  |  '^$'  |  '^' Branch  |  Branch '$'  |  '^' Branch '$'
Branch =  Atom  |  Branch Atom
Atom   =  char  |  quoted_char  |  '.'  |  Bracket  |  Atom Dup  |  '\(' Branch '\)'  |  back_ref
Dup    =  '*'  |  '\{' Count '\}'  |  '\{' Count ',\}'  |  '\{' Count ',' Count '\}'

(leading ^ and trailing $ in a sub expr may be an anchor or literal as well)

ERE grammar:
Regex  =  Branch  |  Regex '|' Branch
Branch =  Atom  |  Branch Atom
Atom   =  char  |  quoted_char  |  '.'  |  Bracket  |  Atom Dup  |  '(' Regex ')'  |  '^'  |  '$'
Dup    =  '*'  |  '+'  |  '?'  |  '{' Count '}'  |  '{' Count ',}'  |  '{' Count ',' Count '}'

(a*+?, ^*, $+, \X, {, (|a) are unspecified)
*/

/* assume \X expansion is a single atom */

/* extensions: \b, \B, \<, \>, \xHH \x{HHHH} */

/* extension: treat \+, \? as repetitions in BRE */

/* reject repetitions after empty expression in BRE */

/* extension: treat \| as alternation in BRE */

/* fallthrough */

/* back reference */

/* extension: accept unknown escaped char
				   as a literal */

/* '^' has a special meaning everywhere in EREs, and at beginning of BRE. */

/* '$' is special everywhere in EREs, and at the end of a BRE subexpression. */

/* reject repetitions after empty expression in ERE */

/* multiple opposite case characters are not supported */

/* extension: treat \+, \? as repetitions in BRE */

/* handle ^* at the start of a BRE. */

/* extension: multiple consecutive *+?{,} is unspecified,
			   but (a+)+ has to be supported so accepting a++ makes
			   sense, note however that the RE_DUP_MAX limit can be
			   circumvented: (a{255}){255} uses a lot of memory.. */

/* extension: treat \| as alternation in BRE */

/* extension: empty branch is unspecified (), (|a), (a|)
			   here they are not rejected but match on empty string */

/***********************************************************************
 from tre-compile.c
***********************************************************************/

/*
  TODO:
   - Fix tre_ast_to_tnfa() to recurse using a stack instead of recursive
     function calls.
*/

/*
  Algorithms to setup tags so that submatch addressing can be done.
*/

/* Inserts a catenation node to the root of the tree given in `node'.
   As the left child a new tag with number `tag_id' to `node' is added,
   and the right child is the old root. */

/* Inserts a catenation node to the root of the tree given in `node'.
   As the right child a new tag with number `tag_id' to `node' is added,
   and the left child is the old root. */

/* Go through `regset' and set submatch data for submatches that are
   using this tag. */

/* Adds tags to appropriate locations in the parse tree in `tree', so that
   subexpressions marked for submatch addressing can be traced. */

/* Tree node we are currently looking at. */

/* True for first pass (counting number of needed tags) */

/* Total number of tags. */

/* Number of special minimal tags. */

/* The tag that is to be added next. */

/* Next tag to use after this one. */

/* Stack of submatches the current submatch is
		       contained in. */

/* Tag that marks the beginning of a minimal match. */

/* Add end of this submatch to regset. */

/* Pop this submatch from the parents stack. */

/* Add start of this submatch to regset. */

/* Add end of this submatch to regset after processing this
		 node. */

/* Regset is not empty, so add a tag before the
			   literal or backref. */

/* After processing right child. */

/* Process right child. */

/* After processing left child. */

/* Reserve the next tag to the right child. */

/* Process left child. */

/* Regset is not empty, so add a tag here. */

/* After processing right child. */

/* Process right child. */

/* After processing left child. */

/* Process left child. */

/* Regset is not empty, so add a tag here. */

/* The next two tags are reserved for markers. */

/* Push this submatch on the parents stack. */

/* end case: ADDTAGS_RECURSE */

/* Lift the bottom of the `regset' array so that when processing
	     the right operand the items currently in the array are
	     invisible.	 The original bottom was saved at ADDTAGS_UNION and
	     will be restored at ADDTAGS_AFTER_UNION_RIGHT below. */

/* Add tags after both children, the left child gets a smaller
	       tag than the right child.  This guarantees that we prefer
	       the left child over the right child. */

/* XXX - This is not always necessary (if the children have
	       tags which must be seen for every match of that child). */

/* XXX - Check if this is the only place where tre_add_tag_right
	       is used.	 If so, use tre_add_tag_left (putting the tag before
	       the child as opposed after the child) and throw away
	       tre_add_tag_right. */

/* end switch(symbol) */

/* end while(tre_stack_num_objects(stack) > bottom) */

/*
  AST to TNFA compilation routines.
*/

/* Flags for tre_copy_ast(). */

/* XXX - e.g. [ab] has only one position but two
		       nodes, so we are creating holes in the state space
		       here.  Not fatal, just wastes memory. */

/* Change this tag to empty. */

/* Maximize the first tag. */

/* Expands each iteration node that has a finite nonzero minimum or maximum
   iteration count to a catenated sequence of copies of the node. */

/* If we are going to expand this node at EXPAND_AFTER_ITER
		   then don't increase the `pos' fields of the nodes now, it
		   will get done when expanding. */

/* Create a catenated sequence of copies of the node. */

/* Remove tags from all but the last copy. */

/* No upper limit. */

/* `max_pos' should never be larger than `*position' if the above
     code works, but just an extra safeguard let's make sure
     `*position' is set large enough so enough memory will be
     allocated for the transition table. */

/* XXX - why not | assertions here as well? */

/* Finds the empty path through `node' which is the one that should be
   taken according to POSIX.2 rules, and adds the tags on that path to
   `tags'.   `tags' may be NULL.  If `num_tags_seen' is not NULL, it is
   set to the number of tags seen on the path. */

/* Walk through the tree recursively. */

/* Add the tag to `tags'. */

/* Subexpressions starting earlier take priority over ones
	     starting later, so we prefer the left subexpression over the
	     right subexpression. */

/* The path must go through both children. */

/* A match with an empty string is preferred over no match at
	     all, so we go through the argument if possible. */

/* Computes and fills in the fields `nullable', `firstpos', and `lastpos' for
   the nodes of the AST `tree'. */

/* Back references: nullable = false, firstpos = {i},
		       lastpos = {i}. */

/* Tags, empty strings, params, and zero width assertions:
		       nullable = true, firstpos = {}, and lastpos = {}. */

/* Literal at position i: nullable = false, firstpos = {i},
		       lastpos = {i}. */

/* Compute the attributes for the two subtrees, and after that
		 for this node. */

/* Compute the attributes for the two subtrees, and after that
		 for this node. */

/* Compute the attributes for the subtree, and after that for
		 this node. */

/* end case: NFL_RECURSE */

/* Compute firstpos. */

/* The left side matches the empty string.  Make a first pass
		   with tre_match_empty() to get the number of tags and
		   parameters. */

/* Allocate arrays for the tags and parameters. */

/* Second pass with tre_mach_empty() to get the list of
		   tags and parameters. */

/* Compute lastpos. */

/* The right side matches the empty string.  Make a first pass
		   with tre_match_empty() to get the number of tags and
		   parameters. */

/* Allocate arrays for the tags and parameters. */

/* Second pass with tre_mach_empty() to get the list of
		   tags and parameters. */

/* Adds a transition from each position in `p1' to each position in `p2'. */

/* Optimization: if this position was already handled, skip it. */

/* Set `trans' to point to the next unused transition from
	       position `p1->position'. */

/* If we find a previous transition from `p1->position' to
		   `p2->position', it is overwritten.  This can happen only
		   if there are nested loops in the regexp, like in "((a)*)*".
		   In POSIX.2 repetition using the outer loop is always
		   preferred over using the inner loop.	 Therefore the
		   transition for the inner loop is useless and can be thrown
		   away. */

/* XXX - The same position is used for all nodes in a bracket
		   expression, so this optimization cannot be used (it will
		   break bracket expressions) unless I figure out a way to
		   detect it here. */

/* Use the character ranges, assertions, etc. from `p1' for
	       the transition from `p1' to `p2'. */

/* Find out how many tags this transition has. */

/* If we are overwriting a transition, free the old tag array. */

/* If there were any tags, allocate an array and fill it. */

/* Don't add duplicates. */

/* Compute a maximum limit for the number of transitions leaving
       from each state. */

/* Converts the syntax tree to a TNFA.	All the transitions in the TNFA are
   labelled with one character range (there are no transitions on empty
   strings).  The TNFA takes O(n^2) space in the worst case, `n' is size of
   the regexp. */

/* XXX - recurse using a stack!. */

/* Add a transition from each position in cat->left->lastpos
	 to each position in cat->right->firstpos. */

/* Add a transition from each last position in the iterated
	     expression to each first position. */

/*CONSTCOND*/

/*CONSTCOND*/

/* Parse context. */

/* Allocate a stack used throughout the compilation process for various
     purposes. */

/* Allocate a fast memory allocator. */

/* Parse the regexp. */

/* TRE_DEBUG */

/* Referring to nonexistent subexpressions is illegal. */

/* Allocate the TNFA struct. */

/* Set up tags for submatch addressing.  If REG_NOSUB is set and the
     regexp does not have back references, this can be skipped. */

/* Figure out how many tags we will need. */

/* Expand iteration nodes. */

/* Add a dummy node for the final state.
     XXX - For certain patterns this dummy node can be optimized away,
	   for example "a*" or "ab*".	Figure out a simple way to detect
	   this possibility. */

/* Copy the arrays p->tags, and p->params, they are allocated
	 from a tre_mem object. */

/* Free everything that was allocated and return the error code. */


=== system/lib/libc/musl/src/regex/regerror.c ===
SHA256: 72b3ab9c63c88c43aa37c4a4d4a89d07f892f42cbbf8801806b7b40135466bb9
Primary Git blob: 5b347cc73c7351b72ec40efa4901818751da7019
/* Error message strings for error codes listed in `regex.h'.  This list
   needs to be in sync with the codes listed there, naturally. */

/* Converted to single string by Rich Felker to remove the need for
 * data relocations at runtime, 27 Feb 2006. */


=== system/lib/libc/musl/src/regex/regexec.c ===
SHA256: 072e8a1092c98830b48e784fb74ce486f7c39e27207f79f1dd161e2c5d86ba77
Primary Git blob: 253b0e1495601567cca31ea27dceca744fcdbfcb
/*
  regexec.c - TRE POSIX compatible matching functions (and more).

  Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

/***********************************************************************
 from tre-match-utils.h
***********************************************************************/

/* Returns 1 if `t1' wins `t2', 0 otherwise. */

/*  assert(0);*/

/* Match. */

/* No match. */

/***********************************************************************
 from tre-match-parallel.c
***********************************************************************/

/*
  This algorithm searches for matches basically by reading characters
  in the searched string one by one, starting at the beginning.	 All
  matching paths in the TNFA are traversed in parallel.	 When two or
  more paths reach the same state, exactly one is chosen according to
  tag ordering rules; if returning submatches is not required it does
  not matter which path is chosen.

  The worst case time required for finding the leftmost and longest
  match, or determining that there is no match, is always linearly
  dependent on the length of the text being searched.

  This algorithm cannot handle TNFAs with back referencing nodes.
  See `tre-match-backtrack.c'.
*/

/* State variables required by GET_NEXT_WCHAR. */

/* TRE_MBSTATE */

/* end offset of match (-1 if no match found yet) */

/* TRE_MBSTATE */

/* Allocate memory for temporary data required for matching.	This needs to
     be done for every matching operation to be thread safe.  This allocates
     everything in a single large block with calloc(). */

/* Ensure that tbytes and xbytes*num_states cannot overflow, and that
     * they don't contribute more than 1/8 of SIZE_MAX to total_bytes. */

/* Likewise check rbytes. */

/* Likewise check pbytes. */

/* Compute the length of the block we need. */

/* for alignment paddings */

/* Allocate the memory. */

/* Get the various pointers within tmp_buf (properly aligned). */

/* If no match found yet, add the initial states to `reach_next'. */

/* We have found a match. */

/* Check for end of string. */

/* Swap `reach' and `reach_next'. */

/* For each state in `reach', weed out states that don't fulfill the
	 minimal matching conditions. */

/* Swap `reach' and `reach_next'. */

/* For each state in `reach' see if there is a transition leaving with
	 the current input symbol to a state not yet in `reach_next', and
	 add the destination states to `reach_next'. */

/* Does this transition match the input symbol? */

/* Compute the tags after this transition. */

/* Found an unvisited node. */

/* Another path has also reached this state.  We choose
			 the winner by examining the tag values for both
			 paths. */

/* The new path wins. */

/***********************************************************************
 from tre-match-backtrack.c
***********************************************************************/

/*
  This matcher is for regexps that use back referencing.  Regexp matching
  with back referencing is an NP-complete problem on the number of back
  references.  The easiest way to match them is to use a backtracking
  routine which basically goes through all possible paths in the TNFA
  and chooses the one which results in the best (leftmost and longest)
  match.  This can be spectacularly expensive and may run out of stack
  space, but there really is no better known generic algorithm.	 Quoting
  Henry Spencer from comp.compilers:
  <URL: http://compilers.iecc.com/comparch/article/93-03-102>

    POSIX.2 REs require longest match, which is really exciting to
    implement since the obsolete ("basic") variant also includes
    \<digit>.  I haven't found a better way of tackling this than doing
    a preliminary match using a DFA (or simulation) on a modified RE
    that just replicates subREs for \<digit>, and then doing a
    backtracking match to determine whether the subRE matches were
    right.  This can be rather slow, but I console myself with the
    thought that people who use \<digit> deserve very slow execution.
    (Pun unintentional but very appropriate.)

*/

/* TRE_MBSTATE */

/* !TRE_MBSTATE */

/* !TRE_MBSTATE */

/* State variables required by GET_NEXT_WCHAR. */

/* TRE_MBSTATE */

/* These are used to remember the necessary values of the above
     variables to return to the position where the current search
     started from. */

/* TRE_MBSTATE */

/* End offset of best match so far, or -1 if no match found yet. */

/* Tag arrays. */

/* Current TNFA state. */

/* Memory allocator to for allocating the backtracking stack. */

/* The backtracking stack. */

/* TRE_MBSTATE */

/* TRE_MBSTATE */

/* Handle initial states. */

/* Start from this state. */

/* Backtrack to this state. */

/* This match wins the previous match. */

/* Our TNFAs never have transitions leaving from the final state,
	     so we jump right to backtracking. */

/* Go to the next character in the input string. */

/* This is a back reference state.  All transitions leaving from
	     this state have the same back reference "assertion".  Instead
	     of reading the next character, we match the back reference. */

/* Get the substring we need to match against.  Remember to
	     turn off REG_NOSUB temporarily. */

/* Back reference matched.  Check for infinite loop. */

/* Advance in input string and resync `prev_c', `next_c'
		 and pos. */

/* Check for end of string. */

/* Read the next character. */

/* First matching transition. */

/* Second matching transition.  We may need to backtrack here
		     to take this transition instead of the first one, so we
		     push this transition in the backtracking stack so we can
		     jump back here if needed. */

/* XXX - it's important not to look at all transitions here to keep
	 the stack small! */

/* Matching transitions were found.  Take the first one. */

/* Update the tag values. */

/* A matching transition was not found.  Try to backtrack. */

/* Try starting from a later position in the input string. */

/* Check for end of string. */

/* TRE_MBSTATE */

/* !TRE_USE_ALLOCA */

/***********************************************************************
 from regexec.c
***********************************************************************/

/* Fills the POSIX.2 regmatch_t array according to the TNFA tag and match
   endpoint values. */

/* Construct submatch offsets from the tags. */

/* If either of the endpoints were not used, this submatch
	     was not part of the match. */

/* Reset all submatches that are not within all of their parent
	 submatches. */

/*
  Wrapper functions for POSIX compatible regexp matching.
*/

/* Dispatch to the appropriate matcher. */

/* The regex has back references, use the backtracking matcher. */

/* Exact matching, no back references, use the parallel matcher. */

/* A match was found, so fill the submatch registers. */


=== system/lib/libc/musl/src/regex/tre-mem.c ===
SHA256: 4721979ce365a395fd7644335c847a8a97913e87f14348641f7f199b57b93e28
Primary Git blob: 86f809d45564ee3190be8d65aac328f97f2882b4
/*
  tre-mem.c - TRE memory allocator

  Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

/*
  This memory allocator is for allocating small memory blocks efficiently
  in terms of memory overhead and execution speed.  The allocated blocks
  cannot be freed individually, only all at once.  There can be multiple
  allocators, though.
*/

/*
  This memory allocator is for allocating small memory blocks efficiently
  in terms of memory overhead and execution speed.  The allocated blocks
  cannot be freed individually, only all at once.  There can be multiple
  allocators, though.
*/

/* Returns a new memory allocator or NULL if out of memory. */

/* Frees the memory allocator and all memory allocated with it. */

/* Allocates a block of `size' bytes from `mem'.  Returns a pointer to the
   allocated block or NULL if an underlying malloc() failed. */

/* We need more memory than is available in the current block.
	 Allocate a new block. */

/* Make sure the next pointer will be aligned. */

/* Allocate from current block. */

/* Set to zero if needed. */


=== system/lib/libc/musl/src/regex/tre.h ===
SHA256: e734e68decc33b5ee983db12cabcbdd2589c2d16088677228087b0e5dc365cf3
Primary Git blob: 9aae851f617af2a577499ed554e3d43ed83764e4
/*
  tre-internal.h - TRE internal definitions

  Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi>
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

    1. Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.

    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

/* Wide characters. */

/* Use system provided iswctype() and wctype(). */

/* Returns number of bytes to add to (char *)ptr to make it
   properly aligned for the type. */

/* TNFA transition type. A TNFA state is an array of transitions,
   the terminator is a transition with NULL `state'. */

/* Range of accepted characters. */

/* Pointer to the destination state. */

/* ID number of the destination state. */

/* -1 terminated array of tags (or NULL). */

/* Assertion bitmap. */

/* Assertion parameters. */

/* Character class assertion. */

/* Back reference assertion. */

/* Negative character class assertions. */

/* Assertions. */

/* Beginning of line. */

/* End of line. */

/* Character class in `class'. */

/* Character classes in `neg_classes'. */

/* Beginning of word. */

/* End of word. */

/* Word boundary. */

/* Not a word boundary. */

/* A back reference in `backref'. */

/* Tag directions. */

/* Instructions to compute submatch register values from tag values
   after a successful match.  */

/* Tag that gives the value for rm_so (submatch start offset). */

/* Tag that gives the value for rm_eo (submatch end offset). */

/* List of submatches this submatch is contained in. */

/* TNFA definition. */

/* from tre-mem.h: */

/* Returns a new memory allocator or NULL if out of memory. */

/* Allocates a block of `size' bytes from `mem'.  Returns a pointer to the
   allocated block or NULL if an underlying malloc() failed. */

/* Allocates a block of `size' bytes from `mem'.  Returns a pointer to the
   allocated block or NULL if an underlying malloc() failed.  The memory
   is set to zero. */

/* alloca() versions.  Like above, but memory is allocated with alloca()
   instead of malloc(). */

/* TRE_USE_ALLOCA */

/* Frees the memory allocator and all memory allocated with it. */


=== system/lib/libc/musl/src/sched/sched_yield.c ===
SHA256: aea797768464e89598bd4887706edfbe7ea27979ea226aca6500f4e915a96e54
Primary Git blob: 7bd3846fc239efc1d7af7c81bf58b11119f47a06
// SharedArrayBuffer and wasm threads do not support explicit yielding.

// For now we at least call `emscripten_yield` which processes the event queue

// (along with other essential tasks).


=== system/lib/libc/musl/src/search/hsearch.c ===
SHA256: f2412d0959655f2aa8f63545ee414fa938875c47f0d081231d036cbf6b1b42e5
Primary Git blob: 2634a67f42f9333f3d3a686c63487eb3bb91fbcb
/*
open addressing hash table with 2^n table size
quadratic probing is used in case of hash collision
tab indices and hash are size_t
after resize fails with ENOMEM the state of tab is still usable

with the posix api items cannot be iterated and length cannot be queried
*/


=== system/lib/libc/musl/src/search/tdelete.c ===
SHA256: b45dba463d919500bfb83bac123490e7fb4b934a4f8665cca684da7b01cbdb1d
Primary Git blob: b8bb924b4e5d09d77bc857ccbd5428416e45f58c
/* *a[0] is an arbitrary non-null pointer that is returned when
	   the root node is deleted.  */

/* free the preceding node instead of the deleted one.  */

/* freed node has at most one child, move it up and rebalance.  */


=== system/lib/libc/musl/src/search/tsearch.c ===
SHA256: 2b694a0b5d5298ae62df241f5729a36016d2ec5f95b2546f7f05d23ff51373dd
Primary Git blob: 0de27d05e94c034285e6de3ba12c9801b40b41db
/* deeper side */

/*
		 *   x
		 *  / \ dir          z
		 * A   y            / \
		 *    / \   -->    x   y
		 *   z   D        /|   |\
		 *  / \          A B   C D
		 * B   C
		 */

/*
		 *   x               y
		 *  / \             / \
		 * A   y    -->    x   D
		 *    / \         / \
		 *   z   D       A   z
		 */

/* balance *p, return 0 if height is unchanged.  */

/* insert new node, rebalance ancestors.  */


=== system/lib/libc/musl/src/search/tsearch.h ===
SHA256: 8d3e27ca196493b5c96f32ba1f1adf0ded1792ca472ec33a6190fb785c2b0722
Primary Git blob: 37d11d7354103b44f7f4cce4f48e865ab8edc3c5
/* AVL tree height < 1.44*log2(nodes+2)-0.3, MAXH is a safe upper bound.  */


=== system/lib/libc/musl/src/select/select.c ===
SHA256: ebab02d163c5e1232ce6bd3f0f5a538d6e26e6f271723742a85ae51f0bef4030
Primary Git blob: 8b5b53335976198ec8b0efc5484a94d5f3eac7d4
// Implement select in terms of `poll()`

// Part 1: convert select arguments into poll arguments

// Part 2: Translate the result of poll into the results of select();

// Map POLLIN to readfds

// POLLHUP/POLLERR usually count as readable (EOF or Error)

// Map POLLOUT to writefds

// POLLERR usually counts as writable (so write fails immediately)

// Map POLLPRI to exceptfds


=== system/lib/libc/musl/src/signal/setitimer.c ===
SHA256: c4b9dd840004ed0c6a869ed3ea1382d5083fc3177591f8b23a5368bea407a603
Primary Git blob: b15986a0c08707f235df8e8ef21acaa20f28fe90
// Timeouts can either fire directly from the JS event loop (which calls

// `_emscripten_timeout`), or from `_emscripten_check_timers` (which is called

// from `_emscripten_yield`).  In order to be able to check the timers here we

// cache the current timeout and interval for each the 3 types of timer

// (ITIMER_PROF/ITIMER_VIRTUAL/ITIMER_REAL).

// If time went backwards, schedule the next timer as if it didn't.

// The next alarm is due 'interval' ms after the previous one.

// If this alarm was delayed, that is sooner than 'interval' ms

// from now. The delay could even be so long that we missed the

// next alarm(s) entirely. Schedule the alarm for the next

// multiple of 'interval' ms from the original due time.

// Only call out to JS to get the current time if it was not passed in

// *and* we have one or more timers set.


=== system/lib/libc/musl/src/stat/fstatat.c ===
SHA256: 73a2e11a9255c67b4470d156ac4b7042ee52706b93283d69b1091b25753be4aa
Primary Git blob: 631451268c590ae20732a6127da4cef212cc8a3c
/* XXX Emscripten: We #define kstat to stat so we can simply make the syscall
 * without the extra copy.
 * See arch/emscripten/kstat.h
 */

// some logic here copied from fstatat_kstat above


=== system/lib/libc/musl/src/stdio/__fdopen.c ===
SHA256: dee65159c3639c6541815cdd528c832ebc13cddae4fc6f1e8d5b5faea03a9938
Primary Git blob: ffc4df718a0b8cc6233dea819b80f9f4010cae52
/* Check for valid initial mode character */

/* Allocate FILE+buffer or fail */

/* Zero-fill only the struct, not the buffer */

/* Impose mode restrictions */

// CLOEXEC makes no sense for a single process

/* Apply close-on-exec flag */

/* Set append mode on fd if opened for append */

/* Activate line buffered mode for terminals */

/* Initialize op ptrs. No problem if some are unneeded. */

/* Add new FILE to open file list */


=== system/lib/libc/musl/src/stdio/__fopen_rb_ca.c ===
SHA256: eb4c953d47e4baae7e50fc8a057b28130495739c68b0578fd2a93290d0796e90
Primary Git blob: 2f3acb831388e326ad238c84564a4254ad2ed38e
// CLOEXEC makes no sense for a single process


=== system/lib/libc/musl/src/stdio/__towrite.c ===
SHA256: b9cb9369502a6d10165bc4b959b4be6a11cfcd43af62d2132d521f860c9bfa4f
Primary Git blob: 4c9c66ae79c9e8c5abe8750df8ebfce149b1e061
/* Clear read buffer (easier than summoning nasal demons) */

/* Activate write through the buffer. */


=== system/lib/libc/musl/src/stdio/__uflow.c ===
SHA256: 08938f226a4dd5246eaa7fd0bd93495763de8fc0d2f7f715a2907e3f4de5fc4f
Primary Git blob: 2a88bca6b123cc2143911783a09a9cac0ce53773
/* This function assumes it will never be called if there is already
 * data buffered for reading. */


=== system/lib/libc/musl/src/stdio/fclose.c ===
SHA256: e6988cb0307c03aedfd2748bbdb5a1d734df728e1db8fbb248a9ff6be1b27b98
Primary Git blob: d594532bd64fdb5695544d67ee4dababd4c9a214
/* Past this point, f is closed and any further explict access
	 * to it is undefined. However, it still exists as an entry in
	 * the open file list and possibly in the thread's locked files
	 * list, if it was closed while explicitly locked. Functions
	 * which process these lists must tolerate dead FILE objects
	 * (which necessarily have inactive buffer pointers) without
	 * producing any side effects. */


=== system/lib/libc/musl/src/stdio/fflush.c ===
SHA256: 856ac1841cdeeeb3df3f47bfbea5fae0746b5c9ac67d9113588f8d1375f6eb55
Primary Git blob: b00943764189901ba6f938714561de7466a5dc38
/* stdout.c will override this if linked */

/* If writing, flush output */

/* If reading, sync position, per POSIX */

/* Clear read and write modes */


=== system/lib/libc/musl/src/stdio/fgetwc.c ===
SHA256: f0367cf2c6fa7a0c97ecf4497b41a74206c98b51dd6781e67e7cbf75d9b0b160
Primary Git blob: aa10b818566a8f1d19af680a9d00458d101572fa
/* Convert character from buffer if possible */

/* l==0 means 1 byte, null */

/* Convert character byte-by-byte */


=== system/lib/libc/musl/src/stdio/fopen.c ===
SHA256: 69a37b32d2229c1302158b2070b1a02016fd4be85cd02985c069fc6ba79607ce
Primary Git blob: 97a5f816af0776e4066c5de3d7c466f82cbab887
/* Check for valid initial mode character */

/* Compute the flags to pass to open() */

// CLOEXEC makes no sense for a single process


=== system/lib/libc/musl/src/stdio/fopencookie.c ===
SHA256: ddb2c119cc721d1d3a936b4b42e15fcff86d7d956b50e3c838e62d8ea547e0bd
Primary Git blob: da042fe8adc37c7468aace6a29ae1c0b3796cc81
/* Check for valid initial mode character */

/* Allocate FILE+fcookie+buffer or fail */

/* Zero-fill only the struct, not the buffer */

/* Impose mode restrictions */

/* Set up our fcookie */

/* Initialize op ptrs. No problem if some are unneeded. */

/* Add new FILE to open file list */


=== system/lib/libc/musl/src/stdio/fprintf.c ===
SHA256: df4f94dd53570727441308bfcd20c6ff4ff95d6c3261bb206a472f81c9df9e1c
Primary Git blob: b8b779767d55d510dc6f383fc859c52b73c1f1af
// XXX EMSCRIPTEN


=== system/lib/libc/musl/src/stdio/fputws.c ===
SHA256: 3d24b90265464fbfccc5a55da53c7c9e0e315bb4d289481a5660911578a3064b
Primary Git blob: 0ed02f1c004e8622e0d4367116a60f22e249720f
/* 0 or -1 */


=== system/lib/libc/musl/src/stdio/fread.c ===
SHA256: d690a3072af0dd833d3cf94569ec0f8ac295b95deb1bfaeb80ca4e693d9c24cc
Primary Git blob: a2116da61370bd829c634353ad6f6fa6732d0d8b
/* First exhaust the buffer. */

/* Read the remainder directly */


=== system/lib/libc/musl/src/stdio/freopen.c ===
SHA256: 466649463abc18546d97ff048dd151c945c48df9ad54527ea5b7b846284f6981
Primary Git blob: 206b5c3eeff218e84c7120bfe77953a2c74001a0
/* The basic idea of this implementation is to open a new FILE,
 * hack the necessary parts of the new FILE into the old one, then
 * close the new FILE. */

/* Locking IS necessary because another thread may provably hold the
 * lock, via flockfile or otherwise, when freopen is called, and in that
 * case, freopen cannot act until the lock is released. */

// CLOEXEC makes no sense for a single process

/* avoid closing in fclose */


=== system/lib/libc/musl/src/stdio/fseek.c ===
SHA256: 69a716a8f8d8601a4d0c9fd24689ec4c43da0a45d8b37a166e91e3517b18aecb
Primary Git blob: c7425802cee7eb8366a8fde5d0da65b9d61ba1fd
/* Fail immediately for invalid whence argument. */

/* Adjust relative offset for unread data in buffer, if any. */

/* Flush write buffer, and report error on failure. */

/* Leave writing mode */

/* Perform the underlying seek. */

/* If seek succeeded, file is seekable and we discard read buffer. */


=== system/lib/libc/musl/src/stdio/ftell.c ===
SHA256: c678b9751a4b5d2c96d070522b42d4e2d02b481efb804cdd799bcdb2f866d35d
Primary Git blob: 1e1a08d8281dc6f7a79b4010adf5302f08716bc3
/* Adjust for data in buffer. */


=== system/lib/libc/musl/src/stdio/fwrite.c ===
SHA256: 91b1cbf23660e909dfe788f1c7cc46e19a937342dbaa357eda1946d2daf5c9c8
Primary Git blob: 7a567b2c55a94b30288444bd93f6fc48fff7e433
/* Match /^(.*\n|)/ */


=== system/lib/libc/musl/src/stdio/getdelim.c ===
SHA256: 2e8ba08543b8d2b8f8ba50af9b934dedf7014698e1e37d1f1fd2830939a48cac
Primary Git blob: df114441c72562a8bfd39e6e1fb3f4687d6715e9
/* Copy as much as fits and ensure no
					 * pushback remains in the FILE buf. */

/* If the byte read by getc won't fit without growing the
		 * output buffer, push it back for next iteration. */


=== system/lib/libc/musl/src/stdio/perror.c ===
SHA256: 68870526f79a3638463309891a006acf6e84303c615ed5eeca1b35179eaab096
Primary Git blob: d0943f26a938bd9dad153c1d64dd88f643c31097
/* Save stderr's orientation and encoding rule, since perror is not
	 * permitted to change them. */


=== system/lib/libc/musl/src/stdio/printf.c ===
SHA256: 58e21fc57a668676b8e855005192ac69583a271cc61563b1fb8f4ffcb73ce429
Primary Git blob: c1722dea59086da06d8dc366f28ab234a105eac7
// XXX EMSCRIPTEN


=== system/lib/libc/musl/src/stdio/setvbuf.c ===
SHA256: 535cc2ebdd0eee2a989f2de5992e48966825ac2860b454325493161d5f07b20a
Primary Git blob: 523dddc8ba28f53a7b3fcc4e3e5323de092acc22
/* The behavior of this function is undefined except when it is the first
 * operation on the stream, so the presence or absence of locking is not
 * observable in a program whose behavior is defined. Thus no locking is
 * performed here. No allocation of buffers is performed, but a buffer
 * provided by the caller is used as long as it is suitably sized. */


=== system/lib/libc/musl/src/stdio/sprintf.c ===
SHA256: cc98d1c5313caa021e5017cc011e6d57bf3dda42111c605e8a9b84b8dd36b3b1
Primary Git blob: 0b984e5e9951b740f0a3c2590c6d6ca65b176d39
// XXX EMSCRIPTEN


=== system/lib/libc/musl/src/stdio/stdout.c ===
SHA256: 66452680f8fa8cac1ad8899aeda0b1eb1fab0756ccef9528b9ef717346674661
Primary Git blob: 62cf40220a5c452fb86713a5719568201ee91b07
// Emscripten doesn't support terminal seeking.

// No special work is needed to close stdout.

// avoid stout_write which adds special terminal window size handling, which emscripten doesn't support anyhow


=== system/lib/libc/musl/src/stdio/vfprintf.c ===
SHA256: 6e135850f0b6bf65e6d0d27206a8a07a57dc0ae91dc1f961d22bd097eadee2a5
Primary Git blob: c0542b599024c3d7a7d9884ff77fd2a7750ef61e
// XXX EMSCRIPTEN - while wasm32 has long double = float128, we don't support

//                  printing at full precision by default. instead, we lower to

//                  64-bit double. These macros makes our changes a little less

//                  invasive.

// EMSCRIPTEN_FULL_LONG_DOUBLE_PRINTING

// XXX EMSCRIPTEN - full long double printing support

/* Some useful macros */

/* Convenient bit representation for modifier flags, which all fall
 * within 31 codepoints of the space character. */

/* State machine to accept length modifiers + conversion specifiers.
 * Result is 0 on failure, or an argument type to pop on success. */

/* 0: bare types */

// 'm' is a gnu extension, and strerror brings in 2.5K of strings

/* 1: l-prefixed */

/* 2: ll-prefixed */

/* 3: h-prefixed */

/* 4: hh-prefixed */

/* 5: L-prefixed */

/* 6: z- or t-prefixed (assumed to be same size) */

/* 7: j-prefixed */

// XXX EMSCRIPTEN -  split out long double, so we don't always link in

//                   long double support for float printf.

/* Do not override this check. The floating point printing code below
 * depends on the float.h constants being right. If they are wrong, it
 * may overflow the stack. */

// XXX EMSCRIPTEN - access fmt_fp indirectly, so that iprintf doesn't 

//                  get it linked in

//                  also use a double argument here, as mentioned before,

//                  we print float128s at double precision 

// mantissa expansion

// exponent expansion

/* Avoid (slow!) computation past requested precision */

/* Perform rounding: j is precision after the radix (possibly neg) */

/* We avoid C's broken division of negative numbers */

/* Are there any significant digits past j? */

/* Decide whether to round by probing round+small */

/* Count trailing zeros in last place */

// XXX EMSCRIPTEN: pass in fmt_fp and pop_arg as a function pointer, so iprintf/__small_printf don't

//                 force linking in of unnecessary floating-point code.

/* This error is only specified for snprintf, but since it's
		 * unspecified for other forms, do the same. Stop immediately
		 * on overflow; otherwise %n could produce wrong results. */

/* Update output count, end loop when fmt is exhausted */

/* Handle literal text and %% format specifiers */

/* Read modifier flags */

/* Read field width */

/* Read precision */

/* Format specifier state machine */

/* Check validity of argument type (nl/normal) */

/* Do not process any new directives once in error state. */

/* Transform ls,lc -> S,C */

/* - and 0 flags are mutually exclusive */

// 'm' is a gnu extension, and strerror brings in 2.5K of strings

// XXX EMSCRIPTEN: pass in fmt_fp and pop_arg as a function pointer, so iprintf/__small_printf don't

//                 force linking in of floating-point code.

/* the copy allows passing va_list* even if va_list is an array */

// XXX EMSCRIPTEN

// XXX EMSCRIPTEN


=== system/lib/libc/musl/src/stdio/vfscanf.c ===
SHA256: d4940fce26d88baa8d0c0f84fb68230c93323f518d0153f0dd293b5c78113b0c
Primary Git blob: b78a374d3a7f4543dacb44832c226b456b7b45dc
/* C or S */

/* do not increment match count, etc! */


=== system/lib/libc/musl/src/stdio/vfwprintf.c ===
SHA256: cbd9abf5ac90ea9510250c925456a5aaf9c70fbb1f3e42d35ef462ee4fb1a641
Primary Git blob: 59d5471baf625fa22321d8aa9a607622feb00ab9
/* Convenient bit representation for modifier flags, which all fall
 * within 31 codepoints of the space character. */

/* State machine to accept length modifiers + conversion specifiers.
 * Result is 0 on failure, or an argument type to pop on success. */

/* 0: bare types */

/* 1: l-prefixed */

/* 2: ll-prefixed */

/* 3: h-prefixed */

/* 4: hh-prefixed */

/* 5: L-prefixed */

/* 6: z- or t-prefixed (assumed to be same size) */

/* 7: j-prefixed */

/* This error is only specified for snprintf, but since it's
		 * unspecified for other forms, do the same. Stop immediately
		 * on overflow; otherwise %n could produce wrong results. */

/* Update output count, end loop when fmt is exhausted */

/* Handle literal text and %% format specifiers */

/* Read modifier flags */

/* Read field width */

/* Read precision */

/* Format specifier state machine */

/* Check validity of argument type (nl/normal) */

/* Do not process any new directives once in error state. */

/* the copy allows passing va_list* even if va_list is an array */


=== system/lib/libc/musl/src/stdio/vfwscanf.c ===
SHA256: 50d29e39b33125dfe03d048918bfde86f1169f6fbfc491986e649fe767cf4def
Primary Git blob: 82f4860441e5b41e52d2e27ddefb2fa1b50ecafb
/* Transform S,C -> ls,lc */

/* do not increment match count, etc! */


=== system/lib/libc/musl/src/stdio/vsnprintf.c ===
SHA256: b307baae1675cf93bab514457dcb6446db7e3bd058d56c209880fc033e7b7668
Primary Git blob: 4d18b50450ef6dd0e7871977d6d9557144650e4a
/* pretend to succeed, even if we discarded extra data */

// XXX EMSCRIPTEN

/* Ensure pointers don't wrap if "infinite" n is passed in */

/* Null-terminate, overwriting last char if dest buffer is full */

/* Ensure pointers don't wrap if "infinite" n is passed in */

/* Null-terminate, overwriting last char if dest buffer is full */


=== system/lib/libc/musl/src/stdio/vsprintf.c ===
SHA256: 9eda84e68f04e3994bcaca864af49b82d127cdc4227ded52401ee54d7273109c
Primary Git blob: c171886f6abf767009594cbfdaedbf22a2a9d535
// XXX EMSCRIPTEN


=== system/lib/libc/musl/src/stdlib/atoi.c ===
SHA256: 76cf48cf82b18f7f5350209e453e5ad003d7a75c60a64b9c5c5d6db0f4e9db27
Primary Git blob: 9baca7b895a0e2f5c3cfab1554f8dcdd280431b9
/* Compute n as a negative number to avoid overflow on INT_MIN */


=== system/lib/libc/musl/src/stdlib/atol.c ===
SHA256: 8262cd55bd64fc505a660ac5736be610fed712e0615553ae561878f3f15ca5e7
Primary Git blob: 140ea3ea3fa27ce690bd61d8a7520efa28e3aad1
/* Compute n as a negative number to avoid overflow on LONG_MIN */


=== system/lib/libc/musl/src/stdlib/atoll.c ===
SHA256: 8d3646e048efde88cceddcc095baa34f9a3f3597539f1153a83aae103bf9b53c
Primary Git blob: b69304895a35c9143ec27ac61ec3a2d24c7a5a59
/* Compute n as a negative number to avoid overflow on LLONG_MIN */


=== system/lib/libc/musl/src/stdlib/qsort.c ===
SHA256: 3a838cc7f83f4746df6063f567be1ebb2f7d204243342122acd43f44d2434ec6
Primary Git blob: 314ddc29da1db7d236044683c264b1a9367b69c1
/* Copyright (C) 2011 by Valentin Ochs
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

/* Minor changes by Rich Felker for integration in musl, 2011-04-27. */

/* Smoothsort, an adaptive variant of Heapsort.  Memory usage: O(1).
   Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */

/* shl() and shr() need n > 0 */

/* Precompute Leonardo numbers, scaled by element width */


=== system/lib/libc/musl/src/stdlib/strtol.c ===
SHA256: a14ecc3dad64193662ed80d66e209013b483e17230eae1d091f33c1cb5aedec2
Primary Git blob: 29a7f1ad749650e5fa1fc4fa1fcfb75c48feb216
// Loosely based on __intscan but simplified, and optimized for size

// - Doesn't use FILE or getc/ungetc, just operates directly on memory

// - Avoids lookup table

// - Avoids special cases loops for certain bases

// - Skips an early exit with EINVAL when char 0 is greater than base.  Its not

//   clear this was correct, and glibc seems not do this either.

// Handle sign

// Handle hex/octal prefix 0x/00

// We exit'd the above loop due to overflow


=== system/lib/libc/musl/src/stdlib/wcstod.c ===
SHA256: b2aa59fd169e699c10d4bd7576ac346550e71a8f04cc75e120e71b4383528e27
Primary Git blob: 0deb7010b1afa1f216b738b3ad128fbc3914ec1a
/* This read function heavily cheats. It knows:
 *  (1) len will always be 1
 *  (2) non-ascii characters don't matter */


=== system/lib/libc/musl/src/stdlib/wcstol.c ===
SHA256: ff9bdb00a80a11494d96617ee22774b433c2bfe1a7b4a8c44c120f4fbc82ac7f
Primary Git blob: 1eeb495fd6eaf2da6b44bae57bfcfd5512b1c838
/* This read function heavily cheats. It knows:
 *  (1) len will always be 1
 *  (2) non-ascii characters don't matter */


=== system/lib/libc/musl/src/string/memchr.c ===
SHA256: 67bfc48f1d29368c9d0ba806112eab32b7a4c1376a7de42e64761a170d7c2dfc
Primary Git blob: bad4e75cc3f38493d5d14b23a890fc30735d8a78
/* XXX EMSCRIPTEN: add __has_feature check */


=== system/lib/libc/musl/src/string/memcmp.c ===
SHA256: 2514492fc7e9249713857dfd12c1a3630661aa163f16bc40a6f59f8cd8e76aeb
Primary Git blob: c93cf8cc97330a9d14cccc40c9303c710488bc22
// XXX EMSCRIPTEN: add an optimized version.

// If we have enough bytes, and everything is aligned, loop on words instead

// of single bytes.

// Go to the single-byte loop to find the specific byte.


=== system/lib/libc/musl/src/string/memmem.c ===
SHA256: 1a17bb31fb38dac1b7e90f521ca4d2a0fe1b249f15d90ea16e89d9af9ce6bd39
Primary Git blob: 11eff86e443e73d5490124f641ce1653f34f53e4
/* Computing length of needle and fill shift table */

/* Compute maximal suffix */

/* And with the opposite comparison */

/* Periodic needle? */

/* Search loop */

/* If remainder of haystack is shorter than needle, done */

/* Check last byte first; advance by shift on mismatch */

/* Compare right half */

/* Compare left half */

/* Return immediately on empty needle */

/* Return immediately when needle is longer than haystack */

/* Use faster algorithms for short needles */


=== system/lib/libc/musl/src/string/stpcpy.c ===
SHA256: 58244549e75540cdc8b5f2d9c0ea7916180962c290fa36b425ba872652df8cd0
Primary Git blob: b3685bf5ac2dc4e331e72282495d4ac3cc864fd2
/* XXX EMSCRIPTEN: add __has_feature check */


=== system/lib/libc/musl/src/string/stpncpy.c ===
SHA256: 4aa7816aeb8e9f0093ec014fed56dc7b9d4808a2ab58adad60d53dc7eddc0255
Primary Git blob: 2e3f67ef3abce468f0812a798a634a45e7590c98
/* XXX EMSCRIPTEN: add __has_feature check */


=== system/lib/libc/musl/src/string/strchrnul.c ===
SHA256: 4282311b1e837ac63df0b091a30bc912e3dc25293f19169ca878bd8d4c329e7c
Primary Git blob: 0ead0dffdcdf6277fe15d81502f094fe281a9fab
/* XXX EMSCRIPTEN: add __has_feature check */


=== system/lib/libc/musl/src/string/strlen.c ===
SHA256: 152cbbb4bf1b99ea4853a0e244e895e2a9c4446cf52b4d6a0c1d4bad5f0106b2
Primary Git blob: aab0719519f6e632901423fcbecb401950298886
/* XXX EMSCRIPTEN: add __has_feature check */


=== system/lib/libc/musl/src/string/strstr.c ===
SHA256: 11158e28318076b70bbaa40c04294b01d02cae475ff72385087c9b966aa14d44
Primary Git blob: 96657bc23114d0fb8662c904d9bc4391ccb16b0f
/* Computing length of needle and fill shift table */

/* hit the end of h */

/* Compute maximal suffix */

/* And with the opposite comparison */

/* Periodic needle? */

/* Initialize incremental end-of-haystack pointer */

/* Search loop */

/* Update incremental end-of-haystack pointer */

/* Fast estimate for MAX(l,63) */

/* Check last byte first; advance by shift on mismatch */

/* Compare right half */

/* Compare left half */

/* Return immediately on empty needle */

/* Use faster algorithms for short needles */


=== system/lib/libc/musl/src/string/strverscmp.c ===
SHA256: a930674aa1b018d6ef5a256e01cd64639f11b1376d151e6a9c979c2b1eba7d82
Primary Git blob: 16c1da224a4d22368f8ed6eb9bc31ffe2229f91f
/* Find maximal matching prefix and track its maximal digit
	 * suffix and whether those digits are all zeros. */

/* If we're looking at non-degenerate digit sequences starting
		 * with nonzero digits, longest digit string is greater. */

/* Otherwise, if common prefix of digit sequence is
		 * all zeros, digits order less than non-digits. */


=== system/lib/libc/musl/src/string/wcsstr.c ===
SHA256: 19fe376f48fa46f416b93cebccf9437a82bbae2bc456a1ef1eabae3950753f1e
Primary Git blob: 4caaef3c94bf1a43ec462264fad90ca914c82da0
/* Computing length of needle */

/* hit the end of h */

/* Compute maximal suffix */

/* And with the opposite comparison */

/* Periodic needle? */

/* Initialize incremental end-of-haystack pointer */

/* Search loop */

/* Update incremental end-of-haystack pointer */

/* Fast estimate for MIN(l,63) */

/* Compare right half */

/* Compare left half */

/* Return immediately on empty needle or haystack */

/* Use faster algorithms for short needles */


=== system/lib/libc/musl/src/temp/__randname.c ===
SHA256: 1c8c11efe1e2eafed9557cb8ac55ee301683a4e83294b199d646d561cc33e095
Primary Git blob: 62152de05b5ede4bf82911c054cc8129c2abee4d
/* This assumes that a check for the
   template size has already been made */

/* XXX EMSCRIPTEN: avoid repeating the same result when __clock_gettime does not change between calls. */


=== system/lib/libc/musl/src/termios/tcsendbreak.c ===
SHA256: 4e4199af08c86ba10a427173a6b13d13ad34fddcbba3d3980ba85bf287ac263a
Primary Git blob: b6df0a23a302431b079f5a02d49fd7bb6422e5b4
/* nonzero duration is implementation-defined, so ignore it */


=== system/lib/libc/musl/src/thread/cnd_broadcast.c ===
SHA256: 0035c1c91877c2102711fa7428f14361b8472b4033809cbb37ade12702318fff
Primary Git blob: e76b5a81bd76cc73524f22ab89766bd4de8e9037
/* This internal function never fails, and always returns zero,
	 * which matches the value thrd_success is defined with. */


=== system/lib/libc/musl/src/thread/cnd_destroy.c ===
SHA256: 131c5ffc8bdc6a67c990090843dd11723715d032b5773f991e073a0835fb7b06
Primary Git blob: 453c90be51072a74e20b3dacb3044f99e1ff1f89
/* For private cv this is a no-op */


=== system/lib/libc/musl/src/thread/cnd_signal.c ===
SHA256: b2f40a604a99b82e7164c8885b4dc40ebf622af937c2d8bf1a2f93a17c9e8a37
Primary Git blob: 02cdc6c60a2550104a0ef09c857205c293c80e10
/* This internal function never fails, and always returns zero,
	 * which matches the value thrd_success is defined with. */


=== system/lib/libc/musl/src/thread/cnd_timedwait.c ===
SHA256: 9d8b67e5adea4908c33093598773d79b4c137791baaafc0e5d5250dc39d585f0
Primary Git blob: 2802af522a50acb12721c377ddd14c7a6373d0ab
/* May also return EINVAL or EPERM. */


=== system/lib/libc/musl/src/thread/cnd_wait.c ===
SHA256: 9fa22068185eecb364d9016f18cfcd81ed22f01b1113b3f2f24bc0fcf090e164
Primary Git blob: 602796f85b5c3c801208c34b0733377e22240173
/* Calling cnd_timedwait with a null pointer is an extension.
	 * It is convenient here to avoid duplication of the logic
	 * for return values. */


=== system/lib/libc/musl/src/thread/mtx_lock.c ===
SHA256: 9e7a0765296e65eb71a3ee7b3277ae613e884fd1a34be69e7cb3b6b747d2e9dd
Primary Git blob: 5c2415c1acdbc5ee1348da1cf43c71557591d8ab
/* Calling mtx_timedlock with a null pointer is an extension.
	 * It is convenient, here to avoid duplication of the logic
	 * for return values. */


=== system/lib/libc/musl/src/thread/mtx_unlock.c ===
SHA256: 5119b40440f1e844215fe45b023c625bc634ff6b96c259ee8baffaf63c23b260
Primary Git blob: 2e5c8cf6bf998f54ca42bc44fa3dda01e533b082
/* The only cases where pthread_mutex_unlock can return an
	 * error are undefined behavior for C11 mtx_unlock, so we can
	 * assume it does not return an error and simply tail call. */


=== system/lib/libc/musl/src/thread/pthread_attr_get.c ===
SHA256: 65588836fda2e91136537dc655f70fa98b344e16152535b03f3b6e4c1160001c
Primary Git blob: 73e30a5f01214073efaa61cc76926478a9051d86
/// XXX musl is not standard-conforming? It should not report EINVAL if _a_stackaddr is zero, and it should

///     report EINVAL if a is null: http://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getstack.html

//	if (!a->_a_stackaddr)

//		return EINVAL;


=== system/lib/libc/musl/src/thread/pthread_getconcurrency.c ===
SHA256: c9c8d235accafa8fd5673ea0018329075077de04ad25655efb12173aeeb18609
Primary Git blob: 4ab5f1b94aeeee3f6383086b9f8fec8c1707b432
// XXX Emscripten marked as obsolescent in pthreads specification:

// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getconcurrency.html


=== system/lib/libc/musl/src/thread/pthread_getcpuclockid.c ===
SHA256: d646231c54e424f36cdd58bf0c706abd540f9151fce070f8ee09f64b9e899630
Primary Git blob: 62355f43ef47d8baa406ccfa77aaf6dbec1479ee
// XXX Emscipten per-thread CPU time clocks are not supported

// pthread API recommends returning this error when "Per-thread CPU time clocks are not supported by the system."


=== system/lib/libc/musl/src/thread/pthread_getschedparam.c ===
SHA256: 859551dcc46c3d7f5781cff6a478138686358d25d9011e43061e0aae5509f131
Primary Git blob: d5931b7b64e5c9c0a75761dd31509f7adac464a1
// XXX Emscripten web or Node workers doesn't support prioritizing threads

// no-op


=== system/lib/libc/musl/src/thread/pthread_setconcurrency.c ===
SHA256: d2b66c7324d118ec448ce51272ddec664ac016a217a14a33ce52043d0094a85d
Primary Git blob: deadf26ba9433517d9d2c82056fa302ac06ecc61
// XXX Emscripten marked as obsolescent in pthreads specification


=== system/lib/libc/musl/src/thread/pthread_setschedprio.c ===
SHA256: 08b967f29751fa20557bf9fe903d807e2c90254eb65f6a4df561e6427f16d952
Primary Git blob: b8d53698683a7e097557851171e413abfea3d149
// XXX Emscripten web or Node workers doesn't support prioritizing threads

// no-op


=== system/lib/libc/musl/src/thread/thrd_create.c ===
SHA256: 328cad9c82a472e5b0fcd98c86422ea9911a3032e3d465110bb34c0f10aa5d7c
Primary Git blob: ca4efb661973b5913011eb198ed142a5b16586c3
// Fix for lsan.  Since lsan wraps calls to the public `pthread_create` function

// if we call the internal __pthread_create function here to don't the wrapping

// See pthread_create wrapper in compiler-rt/lib/lsan/lsan_interceptors.cpp.


=== system/lib/libc/musl/src/thread/thrd_join.c ===
SHA256: 143e333fd2e0914e4bb69f82d3807a20163123f82e3d727b7a79b414a1261758
Primary Git blob: abcdbc1aaeac293cc011499cff1af73e4881cec6
// XXX Emscripten added handling of error case


=== system/lib/libc/musl/src/thread/thrd_sleep.c ===
SHA256: 3322d96b4eff9238ba6a33ae28826527317df08b365f15908a19faafaccc37d7
Primary Git blob: 97de53455ede450885fcd6bdd6bb6de09b97071a
/* value specified by C11 */


=== system/lib/libc/musl/src/thread/tss_create.c ===
SHA256: 8e263dc0e9d556eeefb0e42b93a6a39f528d9ee23e9e1b5c2db207b928bde000
Primary Git blob: 6d6ef96b4c9fb034777eb512462af4ec9c67d172
/* Different error returns are possible. C glues them together into
	 * just failure notification. Can't be optimized to a tail call,
	 * unless thrd_error equals EAGAIN. */


=== system/lib/libc/musl/src/thread/tss_set.c ===
SHA256: 2dbc898eadabcd478ce8028a0b450e47f02f454d5d66de220805dbd45adcce23
Primary Git blob: 70c4fb723cf68b6e37e43477ae8f17d6f6e63b1c
/* Avoid unnecessary COW */


=== system/lib/libc/musl/src/time/__tz.c ===
SHA256: 09d1163cfd10ce56446129497155213b5499216aea5086c6e7016ad17c1225e8
Primary Git blob: 1aac321562e3a8effa7c35ac433246b814dc5aae
/* Cache the old value of TZ to check if it has changed. Avoid
	 * free so as not to pull it into static programs. Growth
	 * strategy makes it so free would have minimal benefit anyway. */

/* Non-suid can use an absolute tzfile pathname or a relative
	 * pathame beginning with "."; in secure mode, only the
	 * standard path will be searched. */

/* Search zoneinfo rules to find the one that applies to the given time,
 * and determine alternate opposite-DST-status rule that may be needed. */

/* Binary search for 'most-recent rule before t'. */

/* First and last entry are special. First means to use lowest-index
	 * non-DST type. Last means to apply POSIX-style rule if available. */

/* Find the lowest non-DST type, or 0 if none. */

/* If t is before first transition, use the above-found type
		 * and the index-zero (after transition) type as the alt. */

/* Try to find a neighboring opposite-DST-status rule. */

/* Convert a POSIX DST rule plus year to seconds since epoch. */

/* Determine the time zone in effect for a given time in seconds since the
 * epoch. It can be given in local or universal time. The results will
 * indicate whether DST is in effect at the queried time, and will give both
 * the GMT offset for the active zone/DST rule and the opposite DST. This
 * enables a caller to efficiently adjust for the case where an explicit
 * DST specification mismatches what would be in effect at the time. */

/* FIXME: may be broken if DST changes right at year boundary?
	 * Also, this could be more efficient.*/


=== system/lib/libc/musl/src/time/asctime_r.c ===
SHA256: ddf7eee8be1f8ed310a2b20fa88f65b5a98210adc6c12babe1fd36353d5316a3
Primary Git blob: 26809ca2676923c6caabee5f30765c371b0301ef
/* ISO C requires us to use the above format string,
		 * even if it will not fit in the buffer. Thus asctime_r
		 * is _supposed_ to crash if the fields in tm are too large.
		 * We follow this behavior and crash "gracefully" to warn
		 * application developers that they may not be so lucky
		 * on other implementations (e.g. stack smashing..).
		 */


=== system/lib/libc/musl/src/time/clock_getres.c ===
SHA256: 68469161bccb9e3daa91db2ef1a3b1e428e501e92c66b32a79b8d99bd0892f18
Primary Git blob: b733fdc00f9d2f2dddff6ba1741e3ee8200f28be
// See https://github.com/bytecodealliance/wasmtime/issues/374

/* On a 32-bit arch, use the old syscall if it exists. */

/* If reaching this point, it's a 64-bit arch or time64-only
	 * 32-bit arch and we can get result directly into timespec. */


=== system/lib/libc/musl/src/time/clock_gettime.c ===
SHA256: 7180a627b02bd8152d1fbafa8fde98960eb1dd06d63d263a0820163e6f12f01d
Primary Git blob: 18926de8ce8f3b46d6c2aca89ddc741f5f12bfbd
/* Fallback to syscalls if time32 overflowed. Maybe
		 * we lucked out and somehow migrated to a kernel with
		 * time64 syscalls available. */

// See https://github.com/bytecodealliance/wasmtime/issues/3714

// __EMSCRIPTEN__

/* Fall through on errors other than EINVAL. Some buggy
		 * vdso implementations return ENOSYS for clocks they
		 * can't handle, rather than making the syscall. This
		 * also handles the case where cgt_init fails to find
		 * a vdso function to use. */

//__EMSCRIPTEN__


=== system/lib/libc/musl/src/time/clock_nanosleep.c ===
SHA256: 65f20ad3d3049e95181d6ea59c045c7a5976521921af51c4578a849523dd8fa0
Primary Git blob: 7ad2aba1a0b7aa602c3581ee1b055a894219457a
// The requested time has already passed


=== system/lib/libc/musl/src/time/clock_settime.c ===
SHA256: 13f0f235c2cf8168c2240095df0d19e1ae0294f49656ae1df9fc3ac255bd0685
Primary Git blob: ed0182fff664c1003591d4129e9dccb673fe8bca
// JS and wasm VMs do not allow setting the time.


=== system/lib/libc/musl/src/time/strftime.c ===
SHA256: aa755a7262f2c0233d9d654b5aead2d673ea4dad32944ddad86a0fd274ed221e
Primary Git blob: 59d609ba922458217fac5eef92e6fe8c18729b00
/* Avoid overflow */

/* If 1 Jan is just 1-3 days past Monday,
	 * the previous week is also in this year. */

/* If 31 December of prev year a Thursday,
		 * or Friday of a leap year, then the
		 * prev year has 53 weeks. */

/* If 1 January is not a Thursday, and not
		 * a Wednesday of a leap year, then this
		 * year has only 52 weeks. */

// Handle trailing % by outputting a % rather than returning 0. Ideally

// this 6 character change could be upstreamed into musl...

/* Trim off any sign and leading zeros, then
			 * count remaining digits to determine behavior
			 * for the + flag. */


=== system/lib/libc/musl/src/time/timespec_get.c ===
SHA256: 166172fc4bee57193d9f5d4017d0dec1db2e351340c01eb53087f480b1c85d33
Primary Git blob: 40ea9c1c32682d25b9f51279588d73f4f170e2a0
/* There is no other implemented value than TIME_UTC; all other values
 * are considered erroneous. */


=== system/lib/libc/musl/src/unistd/dup3.c ===
SHA256: ec099cd70e1be9012079316e406b339927cfa54876cb491974e5ea347e321fe4
Primary Git blob: 311ec4360617a6e7bfdcc2677f5e6237baaaf24e
// CLOEXEC makes no sense for a single process


=== system/lib/libc/musl/src/unistd/fchown.c ===
SHA256: 0ad196e3d12bd88ef81eb6927dfedf41714569cbf6a3211f10f7911adc808d04
Primary Git blob: a3281895054448ac4dc2f7e777664e514d57659c
// We can't continue onwards to try the /proc/fd/NNN approach that musl does,

// as we don't support that much of POSIX.

// EMSCRIPTEN


=== system/lib/libc/musl/src/unistd/getlogin_r.c ===
SHA256: 76207872b13922ecfb5ca8f17c52ddd6e44048b3a8250429e2a9b2946a584d5e
Primary Git blob: 53866c6dce4077d8a53ba118a6460c2f2e6f55ee
/* or...? */


=== system/lib/libc/musl/src/unistd/isatty.c ===
SHA256: 6e888c0de2e0789f54c692b2bc98d4724adc56cbd69b3ebed794598d2bc45ee9
Primary Git blob: 1e41a6edbd1aa07b0c08a57476fddcacdb21b946
// All character devices are terminals (other things a Linux system would

// assume is a character device, like the mouse, we have special APIs for).


=== system/lib/libc/musl/src/unistd/lseek.c ===
SHA256: 0a5ff6af363be25291d771069def7405e76a1b09dc7b988b39eb16abb13540c4
Primary Git blob: 199e784c01d7419c1242027e3a641507ad33b056
// __EMSCRIPTEN__


=== system/lib/libc/musl/src/unistd/nice.c ===
SHA256: 95f992415b2ac41f2b6f60bd1c1a997d535c042562cc75673779c0511d08706a
Primary Git blob: 1c2295ffc6591e7642cf17c352dfce7e168dad73
// Only query old priority if it can affect the result.

// This also avoids issues with integer overflow.


=== system/lib/libc/musl/src/unistd/pipe2.c ===
SHA256: 83f5d38b40f9ce8a3b5675e4cb734b3a32d31bce3559fff2e6c3292690976c0d
Primary Git blob: f215000b31c4d6ac0df0886ecbb1d0907a21d10c
// CLOEXEC makes no sense for a single process


=== system/lib/libc/musl/src/unistd/setxid.c ===
SHA256: d41b909d9023127a431efa3a3213c5c36e2a901fed3475591c2164b3f6fd9998
Primary Git blob: ab707276a32cd471c578af38d8f0bdce2e560f26
// we don't allow dynamic syscalls, and don't need to support these anyhow

/* If one thread fails to set ids after another has already
		 * succeeded, forcibly killing the process is the only safe
		 * thing to do. State is inconsistent and dangerous. Use
		 * SIGKILL because it is uncatchable. */

/* ret is initially nonzero so that failure of the first thread does not
	 * trigger the safety kill above. */


=== system/lib/libc/pthread_sigmask.c ===
SHA256: 70f75a83a597b1fb689ee7aa0dd80ad5129c22c7d8779d824741cc3aa77ceb20
Primary Git blob: f0f137371236354c36f924729c56a3911a1aa519
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// for sigorset/sigandset

// These two signals can never be blocked.

// Raise any pending signals that are now unblocked.


=== system/lib/libc/raise.c ===
SHA256: 38b625a9a367cca608502b43b95c9fefd9e9c289553bad4dd279321c4afe3559
Primary Git blob: 5e56d5cb44221d5dbfe02e76a3f15ac948f1302e
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// for sighandler_t

// Default handler actions ~auto-generated from https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html.

// Note that stop and continue actions are not supported and treated as ignored.

// Prepare to forcibly shut down runtime even if it has async work in flight.

// Intentionally exiting via a function that doesn't call atexit handlers.

// Avoid a direct call to the handler, and instead call via JS so we can

// avoid strict signature checking.

// https://github.com/emscripten-core/posixtestsuite/issues/6


=== system/lib/libc/sigaction.c ===
SHA256: 5033f83e68fe8514fef2a35287bca69c87459f998ee7deb10273eda5203b8bee
Primary Git blob: 080ad45c5a815e2f416e0919d77da5ae08ae3627
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/sigtimedwait.c ===
SHA256: a1063a15f9180ceb388bc32fd2050045eb66060dfdf1ccff8b34898b0488dccc
Primary Git blob: bccedd87323ed5cbe8224f70766ba2ee4977e00a
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */


=== system/lib/libc/wasi-helpers.c ===
SHA256: 6173efcc48a1daacd3c1f7817b18173a6de48a1bb87b1ba49598fa70d22b1731
Primary Git blob: 0eaba304e980eb4438fd9dcddc13c3d30855bbd0
/*
 * Copyright 2019 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// We depend on the fact that wasi codes are identical to our errno codes.


=== system/lib/pthread/library_pthread_stub.c ===
SHA256: b977124314fc0e0329e534ed4f83130a826ff14d8dd46d13896745119a5addb5
Primary Git blob: b0b2e83bb547555f342af755bb7a58d348b38cc4
/*
 * Copyright 2019 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// These low level primites are defined in both pthreads and wasm workers

// builds.

/*uint32_t*/

/*uint32_t*/

// nop

// success

// nop

// nop

// ENOTSUP, while not mentioned in the pthread_create docs, does better

// describe the situation.

// See https://github.com/WebAssembly/wasi-libc/pull/716 for discussion

// on this error code vs, for example, EAGAIN.

// Find empty spot.

// No empty spots, return an error

/*magic number to detect if we have not run yet*/

// pthread_equal is defined as a macro in C, as a function for C++; undef it

// here so we define the function for C++ that links to us.

// XXX implement if/when getpshared is required

// When pthreads is not enabled, we can't use the Atomics futex api to do

// proper sleeps, so simulate a busy spin wait loop instead.


=== system/lib/pthread/proxying_stub.c ===
SHA256: 3999d2656d583b5a844077df0f3b13191f0bdb287d0a444e863d22c7b223e866
Primary Git blob: 0ebb97c2375d97df15cf339e3d263eb7a68c69fc
/*
 * Copyright 2022 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// Stub implementation of the proxying queue API that does nothing, for use in

// single-threaded builds.


=== system/lib/pthread/pthread_self_stub.c ===
SHA256: 5c8d2d2c31c89f962b766385d6743afb6e3d641ffb2d72ef1b0627363b046b12
Primary Git blob: a233f8863c6268644331c28dbad4bb08bd936260
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// In case the stub syscall is not linked it


=== system/lib/pthread/thread_profiler.c ===
SHA256: 854e102bc2281976c56767380d5816d465e3f3469fb20afc580ff17c524ed5a7
Primary Git blob: 5598ed0fb3f5ebfa64590c5d4edf57da9c8df421
/*
 * Copyright 2021 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

// Sets the current thread status, but only if it was in the given expected

// state before. This is used to allow high-level control flow "override" the

// thread status before low-level (futex wait) operations set it.

// AudioWorklets do not have a pthread block, but if user calls emscripten_futex_wait() in an AudioWorklet, it will call here via emscripten_set_current_thread_status().
