@stdlib/math-base-special-rempio2f 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +192 -0
- package/NOTICE +1 -0
- package/README.md +296 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +58 -0
- package/include/stdlib/math/base/special/rempio2f.h +40 -0
- package/lib/index.js +44 -0
- package/lib/kernel_rempio2f.js +410 -0
- package/lib/main.js +138 -0
- package/lib/native.js +53 -0
- package/manifest.json +94 -0
- package/package.json +84 -0
- package/src/addon.c +42 -0
- package/src/main.c +438 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
DEPENDENCIES & ATTRIBUTION
|
|
180
|
+
|
|
181
|
+
The library links against the following external libraries or contains
|
|
182
|
+
implementations from the following external libraries, which have their own
|
|
183
|
+
licenses:
|
|
184
|
+
|
|
185
|
+
* FreeBSD <https://svnweb.freebsd.org/>
|
|
186
|
+
|
|
187
|
+
Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved.
|
|
188
|
+
|
|
189
|
+
Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
190
|
+
Permission to use, copy, modify, and distribute this
|
|
191
|
+
software is freely granted, provided that this notice
|
|
192
|
+
is preserved.
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
# rempio2f
|
|
33
|
+
|
|
34
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
|
+
|
|
36
|
+
> Compute `x - nπ/2 = r` (single-precision).
|
|
37
|
+
|
|
38
|
+
<section class="installation">
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @stdlib/math-base-special-rempio2f
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
</section>
|
|
47
|
+
|
|
48
|
+
<section class="usage">
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
var rempio2f = require( '@stdlib/math-base-special-rempio2f' );
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### rempio2f( x, y )
|
|
57
|
+
|
|
58
|
+
Computes `x - nπ/2 = r`.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
var y = [ 0.0 ];
|
|
62
|
+
var n = rempio2f( 128.0, y );
|
|
63
|
+
// returns 81
|
|
64
|
+
|
|
65
|
+
var y1 = y[ 0 ];
|
|
66
|
+
// returns ~0.765
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
When `x` is `NaN` or infinite, the function returns `0` and sets `y[0]` to `NaN`.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
var y = [ 0.0 ];
|
|
73
|
+
var n = rempio2f( NaN, y );
|
|
74
|
+
// returns 0
|
|
75
|
+
|
|
76
|
+
var y1 = y[ 0 ];
|
|
77
|
+
// returns NaN
|
|
78
|
+
|
|
79
|
+
y = [ 0.0 ];
|
|
80
|
+
n = rempio2f( Infinity, y );
|
|
81
|
+
// returns 0
|
|
82
|
+
|
|
83
|
+
y1 = y[ 0 ];
|
|
84
|
+
// returns NaN
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
</section>
|
|
88
|
+
|
|
89
|
+
<!-- /.usage -->
|
|
90
|
+
|
|
91
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
92
|
+
|
|
93
|
+
<section class="notes">
|
|
94
|
+
|
|
95
|
+
## Notes
|
|
96
|
+
|
|
97
|
+
- The function returns `n` and stores the remainder `r` as `y[0]`.
|
|
98
|
+
- For input values larger than `2^28*π/2` in magnitude, the function **only** returns the last three binary digits of `n` and not the full result.
|
|
99
|
+
|
|
100
|
+
</section>
|
|
101
|
+
|
|
102
|
+
<!-- /.notes -->
|
|
103
|
+
|
|
104
|
+
<section class="examples">
|
|
105
|
+
|
|
106
|
+
## Examples
|
|
107
|
+
|
|
108
|
+
<!-- eslint no-undef: "error" -->
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
var linspace = require( '@stdlib/array-base-linspace' );
|
|
112
|
+
var rempio2f = require( '@stdlib/math-base-special-rempio2f' );
|
|
113
|
+
|
|
114
|
+
var x = linspace( 0.0, 100.0, 100 );
|
|
115
|
+
var y = [ 0.0 ];
|
|
116
|
+
var n;
|
|
117
|
+
var i;
|
|
118
|
+
|
|
119
|
+
for ( i = 0; i < x.length; i++ ) {
|
|
120
|
+
n = rempio2f( x[ i ], y );
|
|
121
|
+
console.log( '%d - %dπ/2 = %d', x[ i ], n, y[ 0 ] );
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
</section>
|
|
126
|
+
|
|
127
|
+
<!-- /.examples -->
|
|
128
|
+
|
|
129
|
+
<!-- C interface documentation. -->
|
|
130
|
+
|
|
131
|
+
* * *
|
|
132
|
+
|
|
133
|
+
<section class="c">
|
|
134
|
+
|
|
135
|
+
## C APIs
|
|
136
|
+
|
|
137
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
138
|
+
|
|
139
|
+
<section class="intro">
|
|
140
|
+
|
|
141
|
+
</section>
|
|
142
|
+
|
|
143
|
+
<!-- /.intro -->
|
|
144
|
+
|
|
145
|
+
<!-- C usage documentation. -->
|
|
146
|
+
|
|
147
|
+
<section class="usage">
|
|
148
|
+
|
|
149
|
+
### Usage
|
|
150
|
+
|
|
151
|
+
```c
|
|
152
|
+
#include "stdlib/math/base/special/rempio2f.h"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### stdlib_base_rempio2f( x, &rem )
|
|
156
|
+
|
|
157
|
+
Computes `x - nπ/2 = r` (single-precision).
|
|
158
|
+
|
|
159
|
+
```c
|
|
160
|
+
#include <stdint.h>
|
|
161
|
+
|
|
162
|
+
double rem;
|
|
163
|
+
|
|
164
|
+
int32_t n = stdlib_base_rempio2f( 4.0f, &rem );
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The function accepts the following arguments:
|
|
168
|
+
|
|
169
|
+
- **x**: `[in] float` input value.
|
|
170
|
+
- **rem**: `[out] double*` destination for the remainder.
|
|
171
|
+
|
|
172
|
+
```c
|
|
173
|
+
int32_t stdlib_base_rempio2f( const float x, double *rem );
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
</section>
|
|
177
|
+
|
|
178
|
+
<!-- /.usage -->
|
|
179
|
+
|
|
180
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
181
|
+
|
|
182
|
+
<section class="notes">
|
|
183
|
+
|
|
184
|
+
</section>
|
|
185
|
+
|
|
186
|
+
<!-- /.notes -->
|
|
187
|
+
|
|
188
|
+
<!-- C API usage examples. -->
|
|
189
|
+
|
|
190
|
+
<section class="examples">
|
|
191
|
+
|
|
192
|
+
### Examples
|
|
193
|
+
|
|
194
|
+
```c
|
|
195
|
+
#include "stdlib/math/base/special/rempio2f.h"
|
|
196
|
+
#include <stdio.h>
|
|
197
|
+
#include <stdint.h>
|
|
198
|
+
#include <inttypes.h>
|
|
199
|
+
|
|
200
|
+
int main( void ) {
|
|
201
|
+
const float x[] = { 0.0f, 1.0f, 4.0f, 128.0f };
|
|
202
|
+
|
|
203
|
+
double rem;
|
|
204
|
+
int32_t n;
|
|
205
|
+
int i;
|
|
206
|
+
for ( i = 0; i < 4; i++ ) {
|
|
207
|
+
n = stdlib_base_rempio2f( x[ i ], &rem );
|
|
208
|
+
printf( "%f - %"PRId32"π/2 = %lf\n", x[ i ], n, rem );
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
</section>
|
|
214
|
+
|
|
215
|
+
<!-- /.examples -->
|
|
216
|
+
|
|
217
|
+
</section>
|
|
218
|
+
|
|
219
|
+
<!-- /.c -->
|
|
220
|
+
|
|
221
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
222
|
+
|
|
223
|
+
<section class="related">
|
|
224
|
+
|
|
225
|
+
</section>
|
|
226
|
+
|
|
227
|
+
<!-- /.related -->
|
|
228
|
+
|
|
229
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
<section class="main-repo" >
|
|
233
|
+
|
|
234
|
+
* * *
|
|
235
|
+
|
|
236
|
+
## Notice
|
|
237
|
+
|
|
238
|
+
This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
|
|
239
|
+
|
|
240
|
+
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
241
|
+
|
|
242
|
+
#### Community
|
|
243
|
+
|
|
244
|
+
[![Chat][chat-image]][chat-url]
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Copyright
|
|
249
|
+
|
|
250
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
251
|
+
|
|
252
|
+
</section>
|
|
253
|
+
|
|
254
|
+
<!-- /.stdlib -->
|
|
255
|
+
|
|
256
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
257
|
+
|
|
258
|
+
<section class="links">
|
|
259
|
+
|
|
260
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-rempio2f.svg
|
|
261
|
+
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-rempio2f
|
|
262
|
+
|
|
263
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-rempio2f/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
264
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-rempio2f/actions/workflows/test.yml?query=branch:v0.1.0
|
|
265
|
+
|
|
266
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-rempio2f/main.svg
|
|
267
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-rempio2f?branch=main
|
|
268
|
+
|
|
269
|
+
<!--
|
|
270
|
+
|
|
271
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-special-rempio2f.svg
|
|
272
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/math-base-special-rempio2f/main
|
|
273
|
+
|
|
274
|
+
-->
|
|
275
|
+
|
|
276
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
277
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
278
|
+
|
|
279
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
280
|
+
|
|
281
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
282
|
+
|
|
283
|
+
[umd]: https://github.com/umdjs/umd
|
|
284
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
285
|
+
|
|
286
|
+
[deno-url]: https://github.com/stdlib-js/math-base-special-rempio2f/tree/deno
|
|
287
|
+
[deno-readme]: https://github.com/stdlib-js/math-base-special-rempio2f/blob/deno/README.md
|
|
288
|
+
[umd-url]: https://github.com/stdlib-js/math-base-special-rempio2f/tree/umd
|
|
289
|
+
[umd-readme]: https://github.com/stdlib-js/math-base-special-rempio2f/blob/umd/README.md
|
|
290
|
+
[esm-url]: https://github.com/stdlib-js/math-base-special-rempio2f/tree/esm
|
|
291
|
+
[esm-readme]: https://github.com/stdlib-js/math-base-special-rempio2f/blob/esm/README.md
|
|
292
|
+
[branches-url]: https://github.com/stdlib-js/math-base-special-rempio2f/blob/main/branches.md
|
|
293
|
+
|
|
294
|
+
</section>
|
|
295
|
+
|
|
296
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";var D=function(l,s){return function(){return s||l((s={exports:{}}).exports,s),s.exports}};var b=D(function(z,_){
|
|
2
|
+
var k=require('@stdlib/math-base-special-floor/dist'),T=require('@stdlib/math-base-special-ldexp/dist'),E=require('@stdlib/array-base-zeros/dist'),M=[10680707,7228996,1387004,2578385,16069853,12639074,9804092,4427841,16666979],B=[1.570796251296997,7549789415861596e-23,5390302529957765e-30,3282003415807913e-37,1270655753080676e-44,12293330898111133e-52,27337005381646456e-60,21674168387780482e-67],N=16777216,P=5960464477539063e-23,d=E(20),h=E(20),A=E(20),u=E(20);function W(l,s,e,c,a,i,x,n,I){var O,f,o,m,r,p,F,t,v;for(m=i,v=c[e],t=e,r=0;t>0;r++)f=P*v|0,u[r]=v-N*f|0,v=c[t-1]+f,t-=1;if(v=T(v,a),v-=8*k(v*.125),F=v|0,v-=F,o=0,a>0?(r=u[e-1]>>24-a,F+=r,u[e-1]-=r<<24-a,o=u[e-1]>>23-a):a===0?o=u[e-1]>>23:v>=.5&&(o=2),o>0){for(F+=1,O=0,r=0;r<e;r++)t=u[r],O===0?t!==0&&(O=1,u[r]=16777216-t):u[r]=16777215-t;if(a>0)switch(a){case 1:u[e-1]&=8388607;break;case 2:u[e-1]&=4194303;break}o===2&&(v=1-v,O!==0&&(v-=T(1,a)))}if(v===0){for(t=0,r=e-1;r>=i;r--)t|=u[r];if(t===0){for(p=1;u[i-p]===0;p++);for(r=e+1;r<=e+p;r++){for(I[n+r]=M[x+r],f=0,t=0;t<=n;t++)f+=l[t]*I[n+(r-t)];c[r]=f}return e+=p,W(l,s,e,c,a,i,x,n,I)}for(e-=1,a-=24;u[e]===0;)e-=1,a-=24}else v=T(v,-a),v>=N?(f=P*v|0,u[e]=v-N*f|0,e+=1,a+=24,u[e]=f):u[e]=v|0;for(f=T(1,a),r=e;r>=0;r--)c[r]=f*u[r],f*=P;for(r=e;r>=0;r--){for(f=0,p=0;p<=m&&p<=e-r;p++)f+=B[p]*c[r+p];A[e-r]=f}for(f=0,r=e;r>=0;r--)f+=A[r];return o===0?s[0]=f:s[0]=-f,F&7}function X(l,s,e,c){var a,i,x,n,I,O,f,o,m;for(i=3,n=c-1,x=(e-3)/24|0,x<0&&(x=0),O=e-24*(x+1),o=x-n,m=n+i,f=0;f<=m;f++)o<0?d[f]=0:d[f]=M[o],o+=1;for(f=0;f<=i;f++){for(a=0,o=0;o<=n;o++)a+=l[o]*d[n+(f-o)];h[f]=a}return I=i,W(l,s,I,h,O,i,x,n,d)}_.exports=X
|
|
3
|
+
});var S=D(function(j,Q){
|
|
4
|
+
var R=require('@stdlib/constants-float32-abs-mask/dist'),U=require('@stdlib/constants-float32-exponent-mask/dist'),V=require('@stdlib/math-base-special-roundf/dist'),Y=require('@stdlib/number-float32-base-from-word/dist'),g=require('@stdlib/number-float32-base-to-word/dist'),C=require('@stdlib/number-float64-base-to-float32/dist'),G=b(),H=.6366197723675814,J=1.5707963109016418,L=15893254773528196e-24,Z=1305022427,K=[0],w=[0];function $(l,s){var e,c,a,i,x,n,I;return l=C(l),c=g(l)|0,a=c&R|0,a<Z?(i=V(C(l*H)),x=l-i*J,n=i*L,s[0]=x-n,i):a>=U?(s[0]=NaN,0):(e=(a>>23)-150,I=Y(a-(e<<23|0)),K[0]=I,i=G(K,w,e,1),c<0?(s[0]=-w[0],-i):(s[0]=w[0],i))}Q.exports=$
|
|
5
|
+
});var y=S();module.exports=y;
|
|
6
|
+
/** @license Apache-2.0 */
|
|
7
|
+
/** @license Apache-2.0 */
|
|
8
|
+
/** @license Apache-2.0 */
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/kernel_rempio2f.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/k_rem_pio2.c}. The implementation follows the original, but has been modified for JavaScript.\n*\n* ```text\n* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n/* eslint-disable array-element-newline */\n\n'use strict';\n\n// MODULES //\n\nvar floor = require( '@stdlib/math-base-special-floor' );\nvar ldexp = require( '@stdlib/math-base-special-ldexp' );\nvar zeros = require( '@stdlib/array-base-zeros' );\n\n\n// VARIABLES //\n\n/*\n* Table of constants for `2/\u03C0` (`396` hex digits, `476` decimal).\n*\n* Integer array which contains the (`24*i`)-th to (`24*i+23`)-th bit of `2/\u03C0` after binary point. The corresponding floating value is\n*\n* ```tex\n* \\operatorname{ipio2}[i] \\cdot 2^{-24(i+1)}\n* ```\n*\n* This table must have at least `(e0-3)/24 + jk` terms. For single precision (`e0 <= 127`, `jk = 3`), this is `9`.\n*/\nvar IPIO2 = [\n\t0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,\n\t0x95993C, 0x439041, 0xFE5163\n];\n\n// Double precision array, obtained by cutting `\u03C0/2` into `24` bits chunks...\nvar PIO2 = [\n\t1.57079625129699707031e+00, // 0x3FF921FB, 0x40000000\n\t7.54978941586159635335e-08, // 0x3E74442D, 0x00000000\n\t5.39030252995776476554e-15, // 0x3CF84698, 0x80000000\n\t3.28200341580791294123e-22, // 0x3B78CC51, 0x60000000\n\t1.27065575308067607349e-29, // 0x39F01B83, 0x80000000\n\t1.22933308981111328932e-36, // 0x387A2520, 0x40000000\n\t2.73370053816464559624e-44, // 0x36E38222, 0x80000000\n\t2.16741683877804819444e-51 // 0x3569F31D, 0x00000000\n];\nvar TWO24 = 1.67772160000000000000e+07; // 0x41700000, 0x00000000\nvar TWON24 = 5.96046447753906250000e-08; // 0x3E700000, 0x00000000\n\n// Arrays for storing temporary values (note that, in C, this is not thread safe):\nvar F = zeros( 20 );\nvar Q = zeros( 20 );\nvar FQ = zeros( 20 );\nvar IQ = zeros( 20 );\n\n\n// FUNCTIONS //\n\n/**\n* Performs the computation for `kernelRempio2f()`.\n*\n* @private\n* @param {PositiveNumber} x - input value\n* @param {(Array|TypedArray|Object)} y - output object for storing double precision numbers\n* @param {integer} jz - number of terms of `ipio2[]` used\n* @param {Array<integer>} q - array with integral values, representing the 24-bits chunk of the product of `x` and `2/\u03C0`\n* @param {integer} q0 - the corresponding exponent of `q[0]` (the exponent for `q[i]` would be `q0-24*i`)\n* @param {integer} jk - `jk+1` is the initial number of terms of `IPIO2[]` needed in the computation\n* @param {integer} jv - index for pointing to the suitable `ipio2[]` for the computation\n* @param {integer} jx - `nx - 1`\n* @param {Array<number>} f - `IPIO2[]` in floating point\n* @returns {number} last three binary digits of `N`\n*/\nfunction compute( x, y, jz, q, q0, jk, jv, jx, f ) {\n\tvar carry;\n\tvar fw;\n\tvar ih;\n\tvar jp;\n\tvar i;\n\tvar k;\n\tvar n;\n\tvar j;\n\tvar z;\n\n\t// `jp+1` is the number of terms in `PIO2[]` needed:\n\tjp = jk;\n\n\t// Distill `q[]` into `IQ[]` in reverse order...\n\tz = q[ jz ];\n\tj = jz;\n\tfor ( i = 0; j > 0; i++ ) {\n\t\tfw = ( TWON24 * z )|0;\n\t\tIQ[ i ] = ( z - (TWO24*fw) )|0;\n\t\tz = q[ j-1 ] + fw;\n\t\tj -= 1;\n\t}\n\t// Compute `n`...\n\tz = ldexp( z, q0 );\n\tz -= 8.0 * floor( z*0.125 ); // Trim off integer >= 8\n\tn = z|0;\n\tz -= n;\n\tih = 0;\n\tif ( q0 > 0 ) {\n\t\t// Need `IQ[jz-1]` to determine `n`...\n\t\ti = ( IQ[ jz-1 ] >> (24-q0) );\n\t\tn += i;\n\t\tIQ[ jz-1 ] -= ( i << (24-q0) );\n\t\tih = ( IQ[ jz-1 ] >> (23-q0) );\n\t}\n\telse if ( q0 === 0 ) {\n\t\tih = ( IQ[ jz-1 ] >> 23 );\n\t}\n\telse if ( z >= 0.5 ) {\n\t\tih = 2;\n\t}\n\t// Case: q > 0.5\n\tif ( ih > 0 ) {\n\t\tn += 1;\n\t\tcarry = 0;\n\n\t\t// Compute `1-q`:\n\t\tfor ( i = 0; i < jz; i++ ) {\n\t\t\tj = IQ[ i ];\n\t\t\tif ( carry === 0 ) {\n\t\t\t\tif ( j !== 0 ) {\n\t\t\t\t\tcarry = 1;\n\t\t\t\t\tIQ[ i ] = 0x1000000 - j;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tIQ[ i ] = 0xffffff - j;\n\t\t\t}\n\t\t}\n\t\tif ( q0 > 0 ) {\n\t\t\t// Rare case: chance is 1 in 12...\n\t\t\tswitch ( q0 ) { // eslint-disable-line default-case\n\t\t\tcase 1:\n\t\t\t\tIQ[ jz-1 ] &= 0x7fffff;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tIQ[ jz-1 ] &= 0x3fffff;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif ( ih === 2 ) {\n\t\t\tz = 1.0 - z;\n\t\t\tif ( carry !== 0 ) {\n\t\t\t\tz -= ldexp( 1.0, q0 );\n\t\t\t}\n\t\t}\n\t}\n\t// Check if re-computation is needed...\n\tif ( z === 0.0 ) {\n\t\tj = 0;\n\t\tfor ( i = jz-1; i >= jk; i-- ) {\n\t\t\tj |= IQ[ i ];\n\t\t}\n\t\tif ( j === 0 ) {\n\t\t\t// Need re-computation...\n\t\t\tfor ( k = 1; IQ[ jk-k ] === 0; k++ ) {\n\t\t\t\t// `k` is the number of terms needed...\n\t\t\t}\n\t\t\tfor ( i = jz+1; i <= jz+k; i++ ) {\n\t\t\t\t// Add `q[jz+1]` to `q[jz+k]`...\n\t\t\t\tf[ jx+i ] = IPIO2[ jv+i ];\n\t\t\t\tfw = 0.0;\n\t\t\t\tfor ( j = 0; j <= jx; j++ ) {\n\t\t\t\t\tfw += x[ j ] * f[ jx + (i-j) ];\n\t\t\t\t}\n\t\t\t\tq[ i ] = fw;\n\t\t\t}\n\t\t\tjz += k;\n\t\t\treturn compute( x, y, jz, q, q0, jk, jv, jx, f );\n\t\t}\n\t\t// Chop off zero terms...\n\t\tjz -= 1;\n\t\tq0 -= 24;\n\t\twhile ( IQ[ jz ] === 0 ) {\n\t\t\tjz -= 1;\n\t\t\tq0 -= 24;\n\t\t}\n\t} else {\n\t\t// Break `z` into 24-bit if necessary...\n\t\tz = ldexp( z, -q0 );\n\t\tif ( z >= TWO24 ) {\n\t\t\tfw = (TWON24*z)|0;\n\t\t\tIQ[ jz ] = ( z - (TWO24*fw) )|0;\n\t\t\tjz += 1;\n\t\t\tq0 += 24;\n\t\t\tIQ[ jz ] = fw;\n\t\t} else {\n\t\t\tIQ[ jz ] = z|0;\n\t\t}\n\t}\n\t// Convert integer \"bit\" chunk to floating-point value...\n\tfw = ldexp( 1.0, q0 );\n\tfor ( i = jz; i >= 0; i-- ) {\n\t\tq[ i ] = fw * IQ[i];\n\t\tfw *= TWON24;\n\t}\n\t// Compute `PIO2[0,...,jp]*q[jz,...,0]`...\n\tfor ( i = jz; i >= 0; i-- ) {\n\t\tfw = 0.0;\n\t\tfor ( k = 0; k <= jp && k <= jz-i; k++ ) {\n\t\t\tfw += PIO2[ k ] * q[ i+k ];\n\t\t}\n\t\tFQ[ jz-i ] = fw;\n\t}\n\t// Compress `FQ[]` into `y[]`...\n\tfw = 0.0;\n\tfor ( i = jz; i >= 0; i-- ) {\n\t\tfw += FQ[ i ];\n\t}\n\tif ( ih === 0 ) {\n\t\ty[ 0 ] = fw;\n\t} else {\n\t\ty[ 0 ] = -fw;\n\t}\n\treturn ( n & 7 );\n}\n\n\n// MAIN //\n\n/**\n* Returns the last three binary digits of `N` with `y = x - N\u03C0/2` so that `|y| < \u03C0/2` (single precision).\n*\n* ## Method\n*\n* - The method is to compute the integer (mod 8) and fraction parts of (2/\u03C0) * 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.\n*\n* - (2/\u03C0) is represented by an array of 24-bit integers in `ipio2[]`.\n*\n* - Input parameters:\n*\n* - `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).\n*\n* Example of breaking a double positive `z` into `x[0]+x[1]+x[2]`:\n*\n* ```tex\n* e0 = \\mathrm{ilogb}(z) - 23\n* z = \\mathrm{scalbn}(z, -e0)\n* ```\n*\n* for `i = 0,1,2`\n*\n* ```tex\n* x[i] = \\lfloor z \\rfloor\n* z = (z - x[i]) \\times 2^{24}\n* ```\n*\n* - `y[]` output result in an array of double precision numbers.\n*\n* The dimension of `y[]` is:\n* 24-bit precision 1\n* 53-bit precision 2\n* 64-bit precision 2\n* 113-bit precision 3\n*\n* The actual value is the sum of them. Thus, for 113-bit precision, one may have to do something like:\n*\n* ```tex\n* \\mathrm{long\\ double} \\: t, w, r_{\\text{head}}, r_{\\text{tail}}; \\\\\n* t &= (\\mathrm{long\\ double}) y[2] + (\\mathrm{long\\ double}) y[1]; \\\\\n* w &= (\\mathrm{long\\ double}) y[0]; \\\\\n* r_{\\text{head}} &= t + w; \\\\\n* r_{\\text{tail}} &= w - (r_{\\text{head}} - t);\n* ```\n*\n* - `e0` The exponent of `x[0]`. Must be <= 16360 or you need to expand the `ipio2` table.\n*\n* - `nx` dimension of `x[]`\n*\n* - `prec` an integer indicating the precision:\n* 0 24 bits (single)\n* 1 53 bits (double)\n* 2 64 bits (extended)\n* 3 113 bits (quad)\n*\n* - External function:\n*\n* - double `scalbn()`, `floor()`;\n*\n* - Here is the description of some local variables:\n*\n* - `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 cancellation before we recompute.)\n*\n* - `jz` local integer variable indicating the number of terms of `ipio2[]` used.\n*\n* - `jx` `nx - 1`\n*\n* - `jv` index for pointing to the suitable `ipio2[]` for the computation. In general, we want\n*\n* ```tex\n* \\frac{{2^{e0} \\cdot x[0] \\cdot \\mathrm{ipio2}[jv-1] \\cdot 2^{-24jv}}}{{8}}\n* ```\n*\n* to be an integer. Thus\n*\n* ```tex\n* e0 - 3 - 24 \\cdot jv \\geq 0 \\quad \\text{or} \\quad \\frac{{e0 - 3}}{{24}} \\geq jv\n* ```\n*\n* Hence\n*\n* ```tex\n* jv = \\max(0, \\frac{{e0 - 3}}{{24}})\n* ```\n*\n* - `jp` `jp+1` is the number of terms in `PIo2[]` needed, `jp = jk`.\n*\n* - `q[]` double array with integral value, representing the 24-bits chunk of the product of `x` and `2/\u03C0`.\n*\n* - `q0` the corresponding exponent of `q[0]`. Note that the exponent for `q[i]` would be `q0-24*i`.\n*\n* - `PIo2[]` double precision array, obtained by cutting `\u03C0/2` into 24 bits chunks.\n*\n* - `f[]` `ipso2[]` in floating point\n*\n* - `iq[]` integer array by breaking up `q[]` in 24-bits chunk.\n*\n* - `fq[]` final product of `x*(2/\u03C0)` in `fq[0],..,fq[jk]`\n*\n* - `ih` integer. If >0 it indicates `q[]` is >= 0.5, hence it also indicates the _sign_ of the result.\n*\n* - Constants:\n*\n* - 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.\n*\n* @private\n* @param {PositiveNumber} x - input value\n* @param {(Array|TypedArray|Object)} y - remainder element\n* @param {PositiveInteger} e0 - the exponent of `x[0]` (must be <= 127)\n* @param {PositiveInteger} nx - dimension of `x[]`\n* @returns {number} last three binary digits of `N`\n*/\nfunction kernelRempio2f( x, y, e0, nx ) {\n\tvar fw;\n\tvar jk;\n\tvar jv;\n\tvar jx;\n\tvar jz;\n\tvar q0;\n\tvar i;\n\tvar j;\n\tvar m;\n\n\t// Initialize `jk` for single-precision floating-point numbers:\n\tjk = 3;\n\n\t// Determine `jx`, `jv`, `q0` (note that `q0 < 3`):\n\tjx = nx - 1;\n\tjv = ( (e0 - 3) / 24 )|0;\n\tif ( jv < 0 ) {\n\t\tjv = 0;\n\t}\n\tq0 = e0 - (24 * (jv + 1));\n\n\t// Set up `F[0]` to `F[jx+jk]` where `F[jx+jk] = IPIO2[jv+jk]`:\n\tj = jv - jx;\n\tm = jx + jk;\n\tfor ( i = 0; i <= m; i++ ) {\n\t\tif ( j < 0 ) {\n\t\t\tF[ i ] = 0.0;\n\t\t} else {\n\t\t\tF[ i ] = IPIO2[ j ];\n\t\t}\n\t\tj += 1;\n\t}\n\t// Compute `Q[0],Q[1],...,Q[jk]`:\n\tfor ( i = 0; i <= jk; i++ ) {\n\t\tfw = 0.0;\n\t\tfor ( j = 0; j <= jx; j++ ) {\n\t\t\tfw += x[ j ] * F[ jx + (i-j) ];\n\t\t}\n\t\tQ[ i ] = fw;\n\t}\n\tjz = jk;\n\treturn compute( x, y, jz, Q, q0, jk, jv, jx, F );\n}\n\n\n// EXPORTS //\n\nmodule.exports = kernelRempio2f;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyright and license were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_rem_pio2f.c}. The implementation follows the original, but has been modified for JavaScript.\n*\n* ```text\n* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n*\n* Optimized by Bruce D. Evans.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ABS_MASK = require( '@stdlib/constants-float32-abs-mask' );\nvar EXPONENT_MASK = require( '@stdlib/constants-float32-exponent-mask' );\nvar roundf = require( '@stdlib/math-base-special-roundf' );\nvar fromWordf = require( '@stdlib/number-float32-base-from-word' );\nvar toWordf = require( '@stdlib/number-float32-base-to-word' );\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar rempio2Kernelf = require( './kernel_rempio2f.js' );\n\n\n// VARIABLES //\n\n// 53 bits of 2/\u03C0:\nvar INVPIO2 = 6.36619772367581382433e-01; // 0x3FE45F30, 0x6DC9C883\n\n// First 25 bits of \u03C0/2:\nvar PIO2_1 = 1.57079631090164184570e+00; // 0x3FF921FB, 0x50000000\n\n// PIO2_1T = \u03C0/2 - PIO2_1:\nvar PIO2_1T = 1.58932547735281966916e-08; // 0x3E5110b4, 0x611A6263\n\n// 2^28*\u03C0/2 = 421657428.2663131 => 0100000110111001001000011111101101010100010001000010110100011000 => high word => 0x4dc90fdb = 1102651899 => 01000001101110010010000111111011\nvar MEDIUM = 0x4dc90fdb|0; // asm type annotation\n\n// Arrays for storing temporary values:\nvar TX = [ 0.0 ];\nvar TY = [ 0.0 ];\n\n\n// MAIN //\n\n/**\n* Computes `x - n\u03C0/2 = r` (single precision).\n*\n* ## Notes\n*\n* - Returns `n` and stores the remainder `r` as `y[0]`.\n*\n* @param {number} x - input value\n* @param {(Array|TypedArray|Object)} y - remainder element\n* @returns {integer} factor of `\u03C0/2`\n*\n* @example\n* var y = [ 0.0 ];\n* var n = rempio2f( 128.0, y );\n* // returns 81\n*\n* var y1 = y[ 0 ];\n* // returns ~0.765\n*\n* @example\n* var y = [ 0.0 ];\n* var n = rempio2f( NaN, y );\n* // returns 0\n*\n* var y1 = y[ 0 ];\n* // returns NaN\n*/\nfunction rempio2f( x, y ) {\n\tvar e0;\n\tvar hx;\n\tvar ix;\n\tvar n;\n\tvar r;\n\tvar w;\n\tvar z;\n\n\tx = float64ToFloat32( x );\n\thx = toWordf( x ) | 0; // asm type annotation\n\tix = (hx & ABS_MASK)|0; // asm type annotation\n\n\t// Case: |x| ~< 2^28*\u03C0/2 (medium size)\n\tif ( ix < MEDIUM ) {\n\t\tn = roundf( float64ToFloat32( x * INVPIO2 ) );\n\t\tr = x - ( n * PIO2_1 );\n\t\tw = n * PIO2_1T;\n\t\ty[ 0 ] = r - w;\n\t\treturn n;\n\t}\n\t// Case: x is NaN or infinity\n\tif ( ix >= EXPONENT_MASK ) {\n\t\ty[ 0 ] = NaN;\n\t\treturn 0;\n\t}\n\t// Set z = scalbn(|x|, ilogb(|x|)-23)...\n\te0 = (ix >> 23) - 150; // `e0 = ilogb(|x|) - 23` => unbiased exponent minus 23\n\tz = fromWordf( ix - ((e0 << 23)|0) );\n\tTX[ 0 ] = z;\n\tn = rempio2Kernelf( TX, TY, e0, 1 );\n\tif ( hx < 0 ) {\n\t\ty[ 0 ] = -TY[ 0 ];\n\t\treturn -n;\n\t}\n\ty[ 0 ] = TY[ 0 ];\n\treturn n;\n}\n\n\n// EXPORTS //\n\nmodule.exports = rempio2f;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute `x - n\u03C0/2 = r` (single precision).\n*\n* @module @stdlib/math-base-special-rempio2f\n*\n* @example\n* var rempio2f = require( '@stdlib/math-base-special-rempio2f' );\n*\n* var y = [ 0.0 ];\n* var n = rempio2f( 128.0, y );\n* // returns 81\n*\n* var y1 = y[ 0 ];\n* // returns ~0.765\n*/\n\n// MODULES //\n\nvar rempio2f = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = rempio2f;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsCA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,0BAA2B,EAgB5CC,EAAQ,CACX,SAAU,QAAU,QAAU,QAAU,SAAU,SAClD,QAAU,QAAU,QACrB,EAGIC,EAAO,CACV,kBACA,qBACA,qBACA,qBACA,qBACA,sBACA,sBACA,qBACD,EACIC,EAAQ,SACRC,EAAS,qBAGTC,EAAIL,EAAO,EAAG,EACdM,EAAIN,EAAO,EAAG,EACdO,EAAKP,EAAO,EAAG,EACfQ,EAAKR,EAAO,EAAG,EAoBnB,SAASS,EAASC,EAAGC,EAAGC,EAAIC,EAAGC,EAAIC,EAAIC,EAAIC,EAAIC,EAAI,CAClD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAQJ,IALAL,EAAKP,EAGLY,EAAId,EAAGD,CAAG,EACVc,EAAId,EACEW,EAAI,EAAGG,EAAI,EAAGH,IACnBH,EAAOhB,EAASuB,EAAI,EACpBnB,EAAIe,CAAE,EAAMI,EAAKxB,EAAMiB,EAAM,EAC7BO,EAAId,EAAGa,EAAE,CAAE,EAAIN,EACfM,GAAK,EAsBN,GAnBAC,EAAI5B,EAAO4B,EAAGb,CAAG,EACjBa,GAAK,EAAM7B,EAAO6B,EAAE,IAAM,EAC1BF,EAAIE,EAAE,EACNA,GAAKF,EACLJ,EAAK,EACAP,EAAK,GAETS,EAAMf,EAAII,EAAG,CAAE,GAAM,GAAGE,EACxBW,GAAKF,EACLf,EAAII,EAAG,CAAE,GAAOW,GAAM,GAAGT,EACzBO,EAAOb,EAAII,EAAG,CAAE,GAAM,GAAGE,GAEhBA,IAAO,EAChBO,EAAOb,EAAII,EAAG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AAUA",
|
|
6
|
+
"names": ["require_kernel_rempio2f", "__commonJSMin", "exports", "module", "floor", "ldexp", "zeros", "IPIO2", "PIO2", "TWO24", "TWON24", "F", "Q", "FQ", "IQ", "compute", "x", "y", "jz", "q", "q0", "jk", "jv", "jx", "f", "carry", "fw", "ih", "jp", "i", "k", "n", "j", "z", "kernelRempio2f", "e0", "nx", "require_main", "__commonJSMin", "exports", "module", "ABS_MASK", "EXPONENT_MASK", "roundf", "fromWordf", "toWordf", "float64ToFloat32", "rempio2Kernelf", "INVPIO2", "PIO2_1", "PIO2_1T", "MEDIUM", "TX", "TY", "rempio2f", "x", "y", "e0", "hx", "ix", "n", "r", "w", "z", "rempio2f"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
import { Collection } from '@stdlib/types/array';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Computes `x - nπ/2 = r` (single-precision).
|
|
27
|
+
*
|
|
28
|
+
* ## Notes
|
|
29
|
+
*
|
|
30
|
+
* - The function returns `n` and stores the remainder `r` as `y[0]`.
|
|
31
|
+
* - For input values larger than `2^28 * π/2` in magnitude, the function only returns the last three binary digits of `n` and not the full result.
|
|
32
|
+
*
|
|
33
|
+
* @param x - input value
|
|
34
|
+
* @param y - remainder element
|
|
35
|
+
* @returns factor of `π/2`
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = [ 0.0 ];
|
|
39
|
+
* var n = rempio2f( 128.0, y );
|
|
40
|
+
* // returns 81
|
|
41
|
+
*
|
|
42
|
+
* var y1 = y[ 0 ];
|
|
43
|
+
* // returns ~0.765
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = [ 0.0 ];
|
|
47
|
+
* var n = rempio2f( NaN, y );
|
|
48
|
+
* // returns 0
|
|
49
|
+
*
|
|
50
|
+
* var y1 = y[ 0 ];
|
|
51
|
+
* // returns NaN
|
|
52
|
+
*/
|
|
53
|
+
declare function rempio2f( x: number, y: Collection<number> ): number;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
export = rempio2f;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef STDLIB_MATH_BASE_SPECIAL_REMPIO2F_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_REMPIO2F_H
|
|
21
|
+
|
|
22
|
+
#include <stdint.h>
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
26
|
+
*/
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
extern "C" {
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Computes `x - nπ/2 = r` (single-precision).
|
|
33
|
+
*/
|
|
34
|
+
int32_t stdlib_base_rempio2f( const float x, double *rem );
|
|
35
|
+
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
}
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_REMPIO2F_H
|