@stdlib/math-base-special-acosf 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 +195 -0
- package/NOTICE +1 -0
- package/README.md +272 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +44 -0
- package/include/stdlib/math/base/special/acosf.h +38 -0
- package/lib/index.js +46 -0
- package/lib/main.js +141 -0
- package/lib/native.js +54 -0
- package/lib/poly_p.js +52 -0
- package/manifest.json +84 -0
- package/package.json +83 -0
- package/src/addon.c +23 -0
- package/src/main.c +160 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
DEPENDENCIES & ATTRIBUTION
|
|
179
|
+
|
|
180
|
+
The library links against the following external libraries or contains
|
|
181
|
+
implementations from the following external libraries, which have their own
|
|
182
|
+
licenses:
|
|
183
|
+
|
|
184
|
+
* Cephes <http://www.netlib.org/cephes/readme>
|
|
185
|
+
|
|
186
|
+
Copyright (c) 1984-2000 Stephen L. Moshier
|
|
187
|
+
|
|
188
|
+
Some software in this archive may be from the book _Methods and Programs for
|
|
189
|
+
Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989)
|
|
190
|
+
or from the Cephes Mathematical Library, a commercial product. In either event,
|
|
191
|
+
it is copyrighted by the author. What you see here may be used freely but it
|
|
192
|
+
comes with no support or guarantee.
|
|
193
|
+
|
|
194
|
+
Stephen L. Moshier
|
|
195
|
+
moshier@na-net.ornl.gov
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2016-2024 The Stdlib Authors.
|
package/README.md
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2024 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
|
+
# acosf
|
|
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 the [arccosine][arccosine] of a single-precision floating-point number.
|
|
37
|
+
|
|
38
|
+
<section class="installation">
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @stdlib/math-base-special-acosf
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
</section>
|
|
47
|
+
|
|
48
|
+
<section class="usage">
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
var acosf = require( '@stdlib/math-base-special-acosf' );
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### acosf( x )
|
|
57
|
+
|
|
58
|
+
Computes the [arccosine][arccosine] of a single-precision floating-point number (in radians).
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
var v = acosf( 1.0 );
|
|
62
|
+
// returns 0.0
|
|
63
|
+
|
|
64
|
+
v = acosf( 0.707 ); // ~pi/4
|
|
65
|
+
// returns ~0.7855
|
|
66
|
+
|
|
67
|
+
v = acosf( 0.866 ); // ~pi/6
|
|
68
|
+
// returns ~0.5236
|
|
69
|
+
|
|
70
|
+
v = acosf( NaN );
|
|
71
|
+
// returns NaN
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The domain of `x` is restricted to `[-1,1]`. If `|x| > 1`, the function returns `NaN`.
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
var v = acosf( -3.14 );
|
|
78
|
+
// returns NaN
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
</section>
|
|
82
|
+
|
|
83
|
+
<!-- /.usage -->
|
|
84
|
+
|
|
85
|
+
<section class="examples">
|
|
86
|
+
|
|
87
|
+
## Examples
|
|
88
|
+
|
|
89
|
+
<!-- eslint no-undef: "error" -->
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
var linspace = require( '@stdlib/array-base-linspace' );
|
|
93
|
+
var acosf = require( '@stdlib/math-base-special-acosf' );
|
|
94
|
+
|
|
95
|
+
var x = linspace( -1.0, 1.0, 100 );
|
|
96
|
+
|
|
97
|
+
var i;
|
|
98
|
+
for ( i = 0; i < x.length; i++ ) {
|
|
99
|
+
console.log( acosf( x[ i ] ) );
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
</section>
|
|
104
|
+
|
|
105
|
+
<!-- /.examples -->
|
|
106
|
+
|
|
107
|
+
<!-- C interface documentation. -->
|
|
108
|
+
|
|
109
|
+
* * *
|
|
110
|
+
|
|
111
|
+
<section class="c">
|
|
112
|
+
|
|
113
|
+
## C APIs
|
|
114
|
+
|
|
115
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
116
|
+
|
|
117
|
+
<section class="intro">
|
|
118
|
+
|
|
119
|
+
</section>
|
|
120
|
+
|
|
121
|
+
<!-- /.intro -->
|
|
122
|
+
|
|
123
|
+
<!-- C usage documentation. -->
|
|
124
|
+
|
|
125
|
+
<section class="usage">
|
|
126
|
+
|
|
127
|
+
### Usage
|
|
128
|
+
|
|
129
|
+
```c
|
|
130
|
+
#include "stdlib/math/base/special/acosf.h"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### stdlib_base_acosf( x )
|
|
134
|
+
|
|
135
|
+
Computes the [arccosine][arccosine] of a single-precision floating-point number (in radians).
|
|
136
|
+
|
|
137
|
+
```c
|
|
138
|
+
float out = stdlib_base_acosf( 1.0f );
|
|
139
|
+
// returns 0.0f
|
|
140
|
+
|
|
141
|
+
out = stdlib_base_acosf( 0.707f ); // ~pi/4
|
|
142
|
+
// returns ~0.7855f
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
The function accepts the following arguments:
|
|
146
|
+
|
|
147
|
+
- **x**: `[in] float` input value (in radians).
|
|
148
|
+
|
|
149
|
+
```c
|
|
150
|
+
float stdlib_base_acosf( const float x );
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
</section>
|
|
154
|
+
|
|
155
|
+
<!-- /.usage -->
|
|
156
|
+
|
|
157
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
158
|
+
|
|
159
|
+
<section class="notes">
|
|
160
|
+
|
|
161
|
+
</section>
|
|
162
|
+
|
|
163
|
+
<!-- /.notes -->
|
|
164
|
+
|
|
165
|
+
<!-- C API usage examples. -->
|
|
166
|
+
|
|
167
|
+
<section class="examples">
|
|
168
|
+
|
|
169
|
+
### Examples
|
|
170
|
+
|
|
171
|
+
```c
|
|
172
|
+
#include "stdlib/math/base/special/acosf.h"
|
|
173
|
+
#include <stdio.h>
|
|
174
|
+
|
|
175
|
+
int main( void ) {
|
|
176
|
+
const float x[] = { -1.0f, -0.78f, -0.56f, -0.33f, -0.11f, 0.11f, 0.33f, 0.56f, 0.78f, 1.0f };
|
|
177
|
+
|
|
178
|
+
float v;
|
|
179
|
+
int i;
|
|
180
|
+
for ( i = 0; i < 10; i++ ) {
|
|
181
|
+
v = stdlib_base_acosf( x[ i ] );
|
|
182
|
+
printf( "acos(%f) = %f\n", x[ i ], v );
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
</section>
|
|
188
|
+
|
|
189
|
+
<!-- /.examples -->
|
|
190
|
+
|
|
191
|
+
</section>
|
|
192
|
+
|
|
193
|
+
<!-- /.c -->
|
|
194
|
+
|
|
195
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
196
|
+
|
|
197
|
+
<section class="related">
|
|
198
|
+
|
|
199
|
+
</section>
|
|
200
|
+
|
|
201
|
+
<!-- /.related -->
|
|
202
|
+
|
|
203
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
<section class="main-repo" >
|
|
207
|
+
|
|
208
|
+
* * *
|
|
209
|
+
|
|
210
|
+
## Notice
|
|
211
|
+
|
|
212
|
+
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.
|
|
213
|
+
|
|
214
|
+
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].
|
|
215
|
+
|
|
216
|
+
#### Community
|
|
217
|
+
|
|
218
|
+
[![Chat][chat-image]][chat-url]
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Copyright
|
|
223
|
+
|
|
224
|
+
Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
225
|
+
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
<!-- /.stdlib -->
|
|
229
|
+
|
|
230
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
231
|
+
|
|
232
|
+
<section class="links">
|
|
233
|
+
|
|
234
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-acosf.svg
|
|
235
|
+
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-acosf
|
|
236
|
+
|
|
237
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-acosf/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
238
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-acosf/actions/workflows/test.yml?query=branch:v0.1.0
|
|
239
|
+
|
|
240
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-acosf/main.svg
|
|
241
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-acosf?branch=main
|
|
242
|
+
|
|
243
|
+
<!--
|
|
244
|
+
|
|
245
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-special-acosf.svg
|
|
246
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/math-base-special-acosf/main
|
|
247
|
+
|
|
248
|
+
-->
|
|
249
|
+
|
|
250
|
+
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
251
|
+
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
|
|
252
|
+
|
|
253
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
254
|
+
|
|
255
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
256
|
+
|
|
257
|
+
[umd]: https://github.com/umdjs/umd
|
|
258
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
259
|
+
|
|
260
|
+
[deno-url]: https://github.com/stdlib-js/math-base-special-acosf/tree/deno
|
|
261
|
+
[deno-readme]: https://github.com/stdlib-js/math-base-special-acosf/blob/deno/README.md
|
|
262
|
+
[umd-url]: https://github.com/stdlib-js/math-base-special-acosf/tree/umd
|
|
263
|
+
[umd-readme]: https://github.com/stdlib-js/math-base-special-acosf/blob/umd/README.md
|
|
264
|
+
[esm-url]: https://github.com/stdlib-js/math-base-special-acosf/tree/esm
|
|
265
|
+
[esm-readme]: https://github.com/stdlib-js/math-base-special-acosf/blob/esm/README.md
|
|
266
|
+
[branches-url]: https://github.com/stdlib-js/math-base-special-acosf/blob/main/branches.md
|
|
267
|
+
|
|
268
|
+
[arccosine]: https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
|
|
269
|
+
|
|
270
|
+
</section>
|
|
271
|
+
|
|
272
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";var O=function(e,v){return function(){return v||e((v={exports:{}}).exports,v),v.exports}};var P=O(function(g,L){
|
|
2
|
+
var s=require('@stdlib/number-float64-base-to-float32/dist');function A(e){return e===0?.16666586697101593:s(.16666586697101593+s(e*s(-.04274342209100723+s(e*-.008656363002955914))))}L.exports=A
|
|
3
|
+
});var _=O(function(h,S){
|
|
4
|
+
var r=require('@stdlib/number-float64-base-to-float32/dist'),M=require('@stdlib/math-base-assert-is-nanf/dist'),d=require('@stdlib/math-base-special-sqrtf/dist'),T=require('@stdlib/math-base-special-absf/dist'),m=require('@stdlib/number-float32-base-to-word/dist'),y=require('@stdlib/number-float32-base-from-word/dist'),F=require('@stdlib/constants-float32-pi/dist'),c=P(),W=3.1415925026,N=1.5707962513,p=75497894159e-18,b=-4096,w=14901161193847656e-24,l=-.7066296339,z=r(N+p);function H(e){var v,o,q,a,i,u,f,t,I,n;return M(e)?NaN:(e=r(e),e<-1||e>1?NaN:e===1?0:e===-1?F:(q=T(e),q<.5?q<=w?z:(a=r(e*e),i=r(a*c(a)),u=r(1+r(a*l)),f=r(i/u),r(N-r(e-r(p-r(e*f))))):e<-.5?(a=r(.5*r(1+e)),i=r(a*c(a)),u=r(1+r(a*l)),t=d(a),f=r(i/u),n=r(r(f*t)-p),r(W-r(2*r(t+n)))):(a=r(.5*r(1-e)),t=d(a),v=m(t),o=y(v&b),I=r(r(a-r(o*o))/r(t+o)),i=r(a*c(a)),u=r(1+r(a*l)),f=r(i/u),n=r(r(f*t)+I),r(2*r(o+n)))))}S.exports=H
|
|
5
|
+
});var K=_();module.exports=K;
|
|
6
|
+
/** @license Apache-2.0 */
|
|
7
|
+
/** @license Apache-2.0 */
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/poly_p.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MODULES //\n\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\n\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.16666586697101593;\n\t}\n\treturn float64ToFloat32(0.16666586697101593 + float64ToFloat32(x * float64ToFloat32(-0.04274342209100723 + float64ToFloat32(x * -0.008656363002955914)))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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, license, and long comment 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_acosf.c?view=markup}. The implementation follows the original, but has been modified according to project conventions.\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'use strict';\n\n// MODULES //\n\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar isnanf = require( '@stdlib/math-base-assert-is-nanf' );\nvar sqrtf = require( '@stdlib/math-base-special-sqrtf' );\nvar absf = require( '@stdlib/math-base-special-absf' );\nvar toWord = require( '@stdlib/number-float32-base-to-word' );\nvar fromWord = require( '@stdlib/number-float32-base-from-word' );\nvar PI = require( '@stdlib/constants-float32-pi' );\nvar polyp = require( './poly_p.js' );\n\n\n// VARIABLES //\n\nvar ALMOST_PI = 3.1415925026e+00; // 0 10000000 10010010000111111011010 => 0x40490fda\nvar PIO2_HI = 1.5707962513e+00; // 0 01111111 10010010000111111011010 => 0x3fc90fda\nvar PIO2_LO = 7.5497894159e-08; // 0 01100111 01000100010000101101000 => 0x33a22168\nvar MASK_LO = 0xfffff000|0; // 1 11111111 11111111111000000000000 => 4294963200 => 0xfffff000\nvar SMALL = 1.4901161193847656e-8; // 2^-26\nvar QS1 = -7.0662963390e-01;\nvar PIO2 = float64ToFloat32( PIO2_HI + PIO2_LO );\n\n\n// MAIN //\n\n/**\n* Computes the arccosine of a single-precision floating-point number.\n*\n* @param {number} x - input value\n* @returns {number} arccosine (in radians)\n*\n* @example\n* var v = acosf( 1.0 );\n* // returns 0.0\n*\n* @example\n* var v = acosf( 0.707 );\n* // returns ~0.7855\n*\n* @example\n* var v = acosf( NaN );\n* // returns NaN\n*/\nfunction acosf( x ) {\n\tvar idf;\n\tvar df;\n\tvar ax;\n\tvar z;\n\tvar p;\n\tvar q;\n\tvar r;\n\tvar s;\n\tvar c;\n\tvar w;\n\n\tif ( isnanf( x ) ) {\n\t\treturn NaN;\n\t}\n\tx = float64ToFloat32( x );\n\tif ( x < -1.0 || x > 1.0 ) {\n\t\treturn NaN;\n\t}\n\tif ( x === 1.0 ) {\n\t\treturn 0.0;\n\t}\n\tif ( x === -1.0 ) {\n\t\treturn PI;\n\t}\n\tax = absf( x );\n\tif ( ax < 0.5 ) {\n\t\tif ( ax <= SMALL ) {\n\t\t\treturn PIO2; // acos(~0) = \u03C0/2\n\t\t}\n\t\tz = float64ToFloat32( x * x );\n\t\tp = float64ToFloat32( z * polyp( z ) );\n\t\tq = float64ToFloat32( 1.0 + float64ToFloat32( z * QS1 ) );\n\t\tr = float64ToFloat32( p / q );\n\t\treturn float64ToFloat32( PIO2_HI - float64ToFloat32( x - float64ToFloat32( PIO2_LO - float64ToFloat32( x * r ) ) ) ); // eslint-disable-line max-len\n\t}\n\tif ( x < -0.5 ) {\n\t\tz = float64ToFloat32( 0.5 * float64ToFloat32( 1.0 + x ) );\n\t\tp = float64ToFloat32( z * polyp( z ) );\n\t\tq = float64ToFloat32( 1.0 + float64ToFloat32( z * QS1 ) );\n\t\ts = sqrtf( z );\n\t\tr = float64ToFloat32( p / q );\n\t\tw = float64ToFloat32( float64ToFloat32( r * s ) - PIO2_LO );\n\t\treturn float64ToFloat32( ALMOST_PI - float64ToFloat32( 2.0 * float64ToFloat32( s + w ) ) ); // eslint-disable-line max-len\n\t}\n\t// x > 0.5\n\tz = float64ToFloat32( 0.5 * float64ToFloat32( 1.0 - x ) );\n\ts = sqrtf( z );\n\n\tidf = toWord( s );\n\tdf = fromWord( idf&MASK_LO );\n\n\tc = float64ToFloat32( float64ToFloat32( z - float64ToFloat32( df * df ) ) / float64ToFloat32( s + df ) ); // eslint-disable-line max-len\n\tp = float64ToFloat32( z * polyp( z ) );\n\tq = float64ToFloat32( 1.0 + float64ToFloat32( z * QS1 ) );\n\tr = float64ToFloat32( p / q );\n\tw = float64ToFloat32( float64ToFloat32( r * s ) + c );\n\treturn float64ToFloat32( 2.0 * float64ToFloat32( df + w ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = acosf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 the arccosine of a single-precision floating-point number.\n*\n* @module @stdlib/math-base-special-acosf\n*\n* @example\n* var acosf = require( '@stdlib/math-base-special-acosf' );\n*\n* var v = acosf( 1.0 );\n* // returns 0.0\n*\n* v = acosf( 0.707 );\n* // returns ~0.7855\n*\n* v = acosf( NaN );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAuBA,IAAIC,EAAmB,QAAS,wCAAyC,EAkBzE,SAASC,EAAUC,EAAI,CACtB,OAAKA,IAAM,EACH,mBAEDF,EAAiB,mBAAsBA,EAAiBE,EAAIF,EAAiB,oBAAuBA,EAAiBE,EAAI,oBAAqB,CAAC,CAAC,CAAC,CACzJ,CAKAH,EAAO,QAAUE,ICnDjB,IAAAE,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAoCA,IAAIC,EAAmB,QAAS,wCAAyC,EACrEC,EAAS,QAAS,kCAAmC,EACrDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,EAAS,QAAS,qCAAsC,EACxDC,EAAW,QAAS,uCAAwC,EAC5DC,EAAK,QAAS,8BAA+B,EAC7CC,EAAQ,IAKRC,EAAY,aACZC,EAAU,aACVC,EAAU,gBACVC,EAAU,MACVC,EAAQ,sBACRC,EAAM,aACNC,EAAOd,EAAkBS,EAAUC,CAAQ,EAuB/C,SAASK,EAAOC,EAAI,CACnB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,OAAKzB,EAAQe,CAAE,EACP,KAERA,EAAIhB,EAAkBgB,CAAE,EACnBA,EAAI,IAAQA,EAAI,EACb,IAEHA,IAAM,EACH,EAEHA,IAAM,GACHV,GAERa,EAAKhB,EAAMa,CAAE,EACRG,EAAK,GACJA,GAAMP,EACHE,GAERM,EAAIpB,EAAkBgB,EAAIA,CAAE,EAC5BK,EAAIrB,EAAkBoB,EAAIb,EAAOa,CAAE,CAAE,EACrCE,EAAItB,EAAkB,EAAMA,EAAkBoB,EAAIP,CAAI,CAAE,EACxDU,EAAIvB,EAAkBqB,EAAIC,CAAE,EACrBtB,EAAkBS,EAAUT,EAAkBgB,EAAIhB,EAAkBU,EAAUV,EAAkBgB,EAAIO,CAAE,CAAE,CAAE,CAAE,GAE/GP,EAAI,KACRI,EAAIpB,EAAkB,GAAMA,EAAkB,EAAMgB,CAAE,CAAE,EACxDK,EAAIrB,EAAkBoB,EAAIb,EAAOa,CAAE,CAAE,EACrCE,EAAItB,EAAkB,EAAMA,EAAkBoB,EAAIP,CAAI,CAAE,EACxDW,EAAItB,EAAOkB,CAAE,EACbG,EAAIvB,EAAkBqB,EAAIC,CAAE,EAC5BI,EAAI1B,EAAkBA,EAAkBuB,EAAIC,CAAE,EAAId,CAAQ,EACnDV,EAAkBQ,EAAYR,EAAkB,EAAMA,EAAkBwB,EAAIE,CAAE,CAAE,CAAE,IAG1FN,EAAIpB,EAAkB,GAAMA,EAAkB,EAAMgB,CAAE,CAAE,EACxDQ,EAAItB,EAAOkB,CAAE,EAEbH,EAAMb,EAAQoB,CAAE,EAChBN,EAAKb,EAAUY,EAAIN,CAAQ,EAE3Bc,EAAIzB,EAAkBA,EAAkBoB,EAAIpB,EAAkBkB,EAAKA,CAAG,CAAE,EAAIlB,EAAkBwB,EAAIN,CAAG,CAAE,EACvGG,EAAIrB,EAAkBoB,EAAIb,EAAOa,CAAE,CAAE,EACrCE,EAAItB,EAAkB,EAAMA,EAAkBoB,EAAIP,CAAI,CAAE,EACxDU,EAAIvB,EAAkBqB,EAAIC,CAAE,EAC5BI,EAAI1B,EAAkBA,EAAkBuB,EAAIC,CAAE,EAAIC,CAAE,EAC7CzB,EAAkB,EAAMA,EAAkBkB,EAAKQ,CAAE,CAAE,IAC3D,CAKA3B,EAAO,QAAUgB,ICpGjB,IAAIY,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_poly_p", "__commonJSMin", "exports", "module", "float64ToFloat32", "evalpoly", "x", "require_main", "__commonJSMin", "exports", "module", "float64ToFloat32", "isnanf", "sqrtf", "absf", "toWord", "fromWord", "PI", "polyp", "ALMOST_PI", "PIO2_HI", "PIO2_LO", "MASK_LO", "SMALL", "QS1", "PIO2", "acosf", "x", "idf", "df", "ax", "z", "p", "q", "r", "s", "c", "w", "main"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
/**
|
|
22
|
+
* Computes the arccosine of a single-precision floating-point number.
|
|
23
|
+
*
|
|
24
|
+
* @param x - input value
|
|
25
|
+
* @returns arccosine (in radians)
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* var v = acosf( 1.0 );
|
|
29
|
+
* // returns 0.0
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* var v = acosf( 0.707 ); // ~pi/4
|
|
33
|
+
* // returns ~0.7855
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var v = acosf( NaN );
|
|
37
|
+
* // returns NaN
|
|
38
|
+
*/
|
|
39
|
+
declare function acosf( x: number ): number;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// EXPORTS //
|
|
43
|
+
|
|
44
|
+
export = acosf;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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_ACOSF_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_ACOSF_H
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
|
|
24
|
+
*/
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Computes the arccosine of a single-precision floating-point number.
|
|
31
|
+
*/
|
|
32
|
+
float stdlib_base_acosf( const float x );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_ACOSF_H
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Compute the arccosine of a single-precision floating-point number.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/math-base-special-acosf
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var acosf = require( '@stdlib/math-base-special-acosf' );
|
|
28
|
+
*
|
|
29
|
+
* var v = acosf( 1.0 );
|
|
30
|
+
* // returns 0.0
|
|
31
|
+
*
|
|
32
|
+
* v = acosf( 0.707 );
|
|
33
|
+
* // returns ~0.7855
|
|
34
|
+
*
|
|
35
|
+
* v = acosf( NaN );
|
|
36
|
+
* // returns NaN
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// MODULES //
|
|
40
|
+
|
|
41
|
+
var main = require( './main.js' );
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// EXPORTS //
|
|
45
|
+
|
|
46
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
* ## Notice
|
|
20
|
+
*
|
|
21
|
+
* The following copyright, license, and long comment 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_acosf.c?view=markup}. The implementation follows the original, but has been modified according to project conventions.
|
|
22
|
+
*
|
|
23
|
+
* ```text
|
|
24
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
25
|
+
*
|
|
26
|
+
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
27
|
+
* Permission to use, copy, modify, and distribute this
|
|
28
|
+
* software is freely granted, provided that this notice
|
|
29
|
+
* is preserved.
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
'use strict';
|
|
34
|
+
|
|
35
|
+
// MODULES //
|
|
36
|
+
|
|
37
|
+
var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
|
|
38
|
+
var isnanf = require( '@stdlib/math-base-assert-is-nanf' );
|
|
39
|
+
var sqrtf = require( '@stdlib/math-base-special-sqrtf' );
|
|
40
|
+
var absf = require( '@stdlib/math-base-special-absf' );
|
|
41
|
+
var toWord = require( '@stdlib/number-float32-base-to-word' );
|
|
42
|
+
var fromWord = require( '@stdlib/number-float32-base-from-word' );
|
|
43
|
+
var PI = require( '@stdlib/constants-float32-pi' );
|
|
44
|
+
var polyp = require( './poly_p.js' );
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// VARIABLES //
|
|
48
|
+
|
|
49
|
+
var ALMOST_PI = 3.1415925026e+00; // 0 10000000 10010010000111111011010 => 0x40490fda
|
|
50
|
+
var PIO2_HI = 1.5707962513e+00; // 0 01111111 10010010000111111011010 => 0x3fc90fda
|
|
51
|
+
var PIO2_LO = 7.5497894159e-08; // 0 01100111 01000100010000101101000 => 0x33a22168
|
|
52
|
+
var MASK_LO = 0xfffff000|0; // 1 11111111 11111111111000000000000 => 4294963200 => 0xfffff000
|
|
53
|
+
var SMALL = 1.4901161193847656e-8; // 2^-26
|
|
54
|
+
var QS1 = -7.0662963390e-01;
|
|
55
|
+
var PIO2 = float64ToFloat32( PIO2_HI + PIO2_LO );
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// MAIN //
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Computes the arccosine of a single-precision floating-point number.
|
|
62
|
+
*
|
|
63
|
+
* @param {number} x - input value
|
|
64
|
+
* @returns {number} arccosine (in radians)
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* var v = acosf( 1.0 );
|
|
68
|
+
* // returns 0.0
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* var v = acosf( 0.707 );
|
|
72
|
+
* // returns ~0.7855
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* var v = acosf( NaN );
|
|
76
|
+
* // returns NaN
|
|
77
|
+
*/
|
|
78
|
+
function acosf( x ) {
|
|
79
|
+
var idf;
|
|
80
|
+
var df;
|
|
81
|
+
var ax;
|
|
82
|
+
var z;
|
|
83
|
+
var p;
|
|
84
|
+
var q;
|
|
85
|
+
var r;
|
|
86
|
+
var s;
|
|
87
|
+
var c;
|
|
88
|
+
var w;
|
|
89
|
+
|
|
90
|
+
if ( isnanf( x ) ) {
|
|
91
|
+
return NaN;
|
|
92
|
+
}
|
|
93
|
+
x = float64ToFloat32( x );
|
|
94
|
+
if ( x < -1.0 || x > 1.0 ) {
|
|
95
|
+
return NaN;
|
|
96
|
+
}
|
|
97
|
+
if ( x === 1.0 ) {
|
|
98
|
+
return 0.0;
|
|
99
|
+
}
|
|
100
|
+
if ( x === -1.0 ) {
|
|
101
|
+
return PI;
|
|
102
|
+
}
|
|
103
|
+
ax = absf( x );
|
|
104
|
+
if ( ax < 0.5 ) {
|
|
105
|
+
if ( ax <= SMALL ) {
|
|
106
|
+
return PIO2; // acos(~0) = π/2
|
|
107
|
+
}
|
|
108
|
+
z = float64ToFloat32( x * x );
|
|
109
|
+
p = float64ToFloat32( z * polyp( z ) );
|
|
110
|
+
q = float64ToFloat32( 1.0 + float64ToFloat32( z * QS1 ) );
|
|
111
|
+
r = float64ToFloat32( p / q );
|
|
112
|
+
return float64ToFloat32( PIO2_HI - float64ToFloat32( x - float64ToFloat32( PIO2_LO - float64ToFloat32( x * r ) ) ) ); // eslint-disable-line max-len
|
|
113
|
+
}
|
|
114
|
+
if ( x < -0.5 ) {
|
|
115
|
+
z = float64ToFloat32( 0.5 * float64ToFloat32( 1.0 + x ) );
|
|
116
|
+
p = float64ToFloat32( z * polyp( z ) );
|
|
117
|
+
q = float64ToFloat32( 1.0 + float64ToFloat32( z * QS1 ) );
|
|
118
|
+
s = sqrtf( z );
|
|
119
|
+
r = float64ToFloat32( p / q );
|
|
120
|
+
w = float64ToFloat32( float64ToFloat32( r * s ) - PIO2_LO );
|
|
121
|
+
return float64ToFloat32( ALMOST_PI - float64ToFloat32( 2.0 * float64ToFloat32( s + w ) ) ); // eslint-disable-line max-len
|
|
122
|
+
}
|
|
123
|
+
// x > 0.5
|
|
124
|
+
z = float64ToFloat32( 0.5 * float64ToFloat32( 1.0 - x ) );
|
|
125
|
+
s = sqrtf( z );
|
|
126
|
+
|
|
127
|
+
idf = toWord( s );
|
|
128
|
+
df = fromWord( idf&MASK_LO );
|
|
129
|
+
|
|
130
|
+
c = float64ToFloat32( float64ToFloat32( z - float64ToFloat32( df * df ) ) / float64ToFloat32( s + df ) ); // eslint-disable-line max-len
|
|
131
|
+
p = float64ToFloat32( z * polyp( z ) );
|
|
132
|
+
q = float64ToFloat32( 1.0 + float64ToFloat32( z * QS1 ) );
|
|
133
|
+
r = float64ToFloat32( p / q );
|
|
134
|
+
w = float64ToFloat32( float64ToFloat32( r * s ) + c );
|
|
135
|
+
return float64ToFloat32( 2.0 * float64ToFloat32( df + w ) );
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// EXPORTS //
|
|
140
|
+
|
|
141
|
+
module.exports = acosf;
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Computes the arccosine of a single-precision floating-point number.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @returns {number} arccosine (in radians)
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var v = acosf( 1.0 );
|
|
37
|
+
* // returns 0.0
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var v = acosf( 0.707 );
|
|
41
|
+
* // returns ~0.7855
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var v = acosf( NaN );
|
|
45
|
+
* // returns NaN
|
|
46
|
+
*/
|
|
47
|
+
function acosf( x ) {
|
|
48
|
+
return addon( x );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = acosf;
|
package/lib/poly_p.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
/* This is a generated file. Do not edit directly. */
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
// MODULES //
|
|
23
|
+
|
|
24
|
+
var float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Evaluates a polynomial.
|
|
31
|
+
*
|
|
32
|
+
* ## Notes
|
|
33
|
+
*
|
|
34
|
+
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
|
|
35
|
+
*
|
|
36
|
+
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
|
|
37
|
+
*
|
|
38
|
+
* @private
|
|
39
|
+
* @param {number} x - value at which to evaluate the polynomial
|
|
40
|
+
* @returns {number} evaluated polynomial
|
|
41
|
+
*/
|
|
42
|
+
function evalpoly( x ) {
|
|
43
|
+
if ( x === 0.0 ) {
|
|
44
|
+
return 0.16666586697101593;
|
|
45
|
+
}
|
|
46
|
+
return float64ToFloat32(0.16666586697101593 + float64ToFloat32(x * float64ToFloat32(-0.04274342209100723 + float64ToFloat32(x * -0.008656363002955914)))); // eslint-disable-line max-len
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// EXPORTS //
|
|
51
|
+
|
|
52
|
+
module.exports = evalpoly;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build"
|
|
4
|
+
},
|
|
5
|
+
"fields": [
|
|
6
|
+
{
|
|
7
|
+
"field": "src",
|
|
8
|
+
"resolve": true,
|
|
9
|
+
"relative": true
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"field": "include",
|
|
13
|
+
"resolve": true,
|
|
14
|
+
"relative": true
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"field": "libraries",
|
|
18
|
+
"resolve": false,
|
|
19
|
+
"relative": false
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"field": "libpath",
|
|
23
|
+
"resolve": true,
|
|
24
|
+
"relative": false
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"confs": [
|
|
28
|
+
{
|
|
29
|
+
"task": "build",
|
|
30
|
+
"src": [
|
|
31
|
+
"./src/main.c"
|
|
32
|
+
],
|
|
33
|
+
"include": [
|
|
34
|
+
"./include"
|
|
35
|
+
],
|
|
36
|
+
"libraries": [],
|
|
37
|
+
"libpath": [],
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"@stdlib/math-base-napi-unary",
|
|
40
|
+
"@stdlib/math-base-assert-is-nanf",
|
|
41
|
+
"@stdlib/math-base-special-sqrtf",
|
|
42
|
+
"@stdlib/constants-float32-abs-mask",
|
|
43
|
+
"@stdlib/number-float32-base-from-word",
|
|
44
|
+
"@stdlib/number-float32-base-to-word"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"task": "benchmark",
|
|
49
|
+
"src": [
|
|
50
|
+
"./src/main.c"
|
|
51
|
+
],
|
|
52
|
+
"include": [
|
|
53
|
+
"./include"
|
|
54
|
+
],
|
|
55
|
+
"libraries": [],
|
|
56
|
+
"libpath": [],
|
|
57
|
+
"dependencies": [
|
|
58
|
+
"@stdlib/math-base-assert-is-nanf",
|
|
59
|
+
"@stdlib/math-base-special-sqrtf",
|
|
60
|
+
"@stdlib/constants-float32-abs-mask",
|
|
61
|
+
"@stdlib/number-float32-base-from-word",
|
|
62
|
+
"@stdlib/number-float32-base-to-word"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"task": "examples",
|
|
67
|
+
"src": [
|
|
68
|
+
"./src/main.c"
|
|
69
|
+
],
|
|
70
|
+
"include": [
|
|
71
|
+
"./include"
|
|
72
|
+
],
|
|
73
|
+
"libraries": [],
|
|
74
|
+
"libpath": [],
|
|
75
|
+
"dependencies": [
|
|
76
|
+
"@stdlib/math-base-assert-is-nanf",
|
|
77
|
+
"@stdlib/math-base-special-sqrtf",
|
|
78
|
+
"@stdlib/constants-float32-abs-mask",
|
|
79
|
+
"@stdlib/number-float32-base-from-word",
|
|
80
|
+
"@stdlib/number-float32-base-to-word"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/math-base-special-acosf",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compute the arccosine of a single-precision floating-point number.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
18
|
+
"directories": {
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"scripts": "./scripts",
|
|
23
|
+
"src": "./src",
|
|
24
|
+
"dist": "./dist"
|
|
25
|
+
},
|
|
26
|
+
"types": "./docs/types",
|
|
27
|
+
"scripts": {},
|
|
28
|
+
"homepage": "https://stdlib.io",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git://github.com/stdlib-js/math-base-special-acosf.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@stdlib/constants-float32-abs-mask": "^0.2.1",
|
|
38
|
+
"@stdlib/constants-float32-pi": "github:stdlib-js/constants-float32-pi#main",
|
|
39
|
+
"@stdlib/math-base-assert-is-nanf": "^0.2.1",
|
|
40
|
+
"@stdlib/math-base-napi-unary": "^0.2.1",
|
|
41
|
+
"@stdlib/math-base-special-absf": "^0.2.1",
|
|
42
|
+
"@stdlib/math-base-special-sqrtf": "^0.2.1",
|
|
43
|
+
"@stdlib/number-float32-base-from-word": "^0.2.1",
|
|
44
|
+
"@stdlib/number-float32-base-to-word": "^0.2.1",
|
|
45
|
+
"@stdlib/number-float64-base-to-float32": "^0.2.1",
|
|
46
|
+
"@stdlib/utils-library-manifest": "^0.2.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=0.10.0",
|
|
51
|
+
"npm": ">2.7.0"
|
|
52
|
+
},
|
|
53
|
+
"os": [
|
|
54
|
+
"aix",
|
|
55
|
+
"darwin",
|
|
56
|
+
"freebsd",
|
|
57
|
+
"linux",
|
|
58
|
+
"macos",
|
|
59
|
+
"openbsd",
|
|
60
|
+
"sunos",
|
|
61
|
+
"win32",
|
|
62
|
+
"windows"
|
|
63
|
+
],
|
|
64
|
+
"keywords": [
|
|
65
|
+
"stdlib",
|
|
66
|
+
"stdmath",
|
|
67
|
+
"mathematics",
|
|
68
|
+
"math",
|
|
69
|
+
"math.acos",
|
|
70
|
+
"acosf",
|
|
71
|
+
"arccosine",
|
|
72
|
+
"cosine",
|
|
73
|
+
"inverse",
|
|
74
|
+
"trig",
|
|
75
|
+
"trigonometry",
|
|
76
|
+
"radians",
|
|
77
|
+
"angle"
|
|
78
|
+
],
|
|
79
|
+
"funding": {
|
|
80
|
+
"type": "opencollective",
|
|
81
|
+
"url": "https://opencollective.com/stdlib"
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
#include "stdlib/math/base/special/acosf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/unary.h"
|
|
21
|
+
|
|
22
|
+
// cppcheck-suppress shadowFunction
|
|
23
|
+
STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_acosf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
* ## Notice
|
|
20
|
+
*
|
|
21
|
+
* The following copyright, license, and long comment 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_acosf.c?view=markup}. The implementation follows the original, but has been modified according to project conventions.
|
|
22
|
+
*
|
|
23
|
+
* ```text
|
|
24
|
+
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
25
|
+
*
|
|
26
|
+
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
27
|
+
* Permission to use, copy, modify, and distribute this
|
|
28
|
+
* software is freely granted, provided that this notice
|
|
29
|
+
* is preserved.
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
#include "stdlib/math/base/special/acosf.h"
|
|
34
|
+
#include "stdlib/math/base/assert/is_nanf.h"
|
|
35
|
+
#include "stdlib/math/base/special/sqrtf.h"
|
|
36
|
+
#include "stdlib/number/float32/base/from_word.h"
|
|
37
|
+
#include "stdlib/number/float32/base/to_word.h"
|
|
38
|
+
#include "stdlib/constants/float32/abs_mask.h"
|
|
39
|
+
#include <stdint.h>
|
|
40
|
+
|
|
41
|
+
static const float ALMOST_PI = 3.1415925026e+00f; // 0 10000000 10010010000111111011010 => 0x40490fda
|
|
42
|
+
static const float PIO2_HI = 1.5707962513e+00f; // 0 01111111 10010010000111111011010 => 0x3fc90fda
|
|
43
|
+
static volatile float PIO2_LO = 7.5497894159e-08f; // 0 01100111 01000100010000101101000 => 0x33a22168
|
|
44
|
+
static const int32_t ONE = 0x3f800000; // 1.0 => 0 01111111 00000000000000000000000 => 1065353216 => 0x3f800000
|
|
45
|
+
static const int32_t ONE_HALF = 0x3f000000; // 0.5 => 0 01111110 00000000000000000000000 => 1056964608 => 0x3f000000
|
|
46
|
+
static const int32_t SMALL = 0x32800000; // 2^-26 => 0 01100101 00000000000000000000000 => 847249408 => 0x32800000
|
|
47
|
+
static const int32_t MASK_LO = 0xfffff000; // 1 11111111 11111111111000000000000 => 4294963200 => 0xfffff000
|
|
48
|
+
static const float QS1 = -7.0662963390e-01;
|
|
49
|
+
|
|
50
|
+
/* Begin auto-generated functions. The following functions are auto-generated. Do not edit directly. */
|
|
51
|
+
|
|
52
|
+
// BEGIN: poly_p
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Evaluates a polynomial.
|
|
56
|
+
*
|
|
57
|
+
* ## Notes
|
|
58
|
+
*
|
|
59
|
+
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
|
|
60
|
+
*
|
|
61
|
+
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
|
|
62
|
+
*
|
|
63
|
+
* @param x value at which to evaluate the polynomial
|
|
64
|
+
* @return evaluated polynomial
|
|
65
|
+
*/
|
|
66
|
+
static float poly_p( const float x ) {
|
|
67
|
+
return 0.16666586697f + (x * (-0.042743422091f + (x * -0.008656363003f)));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// END: poly_p
|
|
71
|
+
|
|
72
|
+
/* End auto-generated functions. */
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Computes the arccosine of a single-precision floating-point number.
|
|
76
|
+
*
|
|
77
|
+
* @param x input value
|
|
78
|
+
* @return arccosine (in radians)
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* float out = stdlib_base_acosf( 1.0f );
|
|
82
|
+
* // returns 0.0f
|
|
83
|
+
*/
|
|
84
|
+
float stdlib_base_acosf( const float x ) {
|
|
85
|
+
uint32_t uidf;
|
|
86
|
+
uint32_t uhx;
|
|
87
|
+
int32_t idf;
|
|
88
|
+
int32_t hx;
|
|
89
|
+
int32_t ix;
|
|
90
|
+
float df;
|
|
91
|
+
float z;
|
|
92
|
+
float p;
|
|
93
|
+
float q;
|
|
94
|
+
float r;
|
|
95
|
+
float w;
|
|
96
|
+
float s;
|
|
97
|
+
float c;
|
|
98
|
+
|
|
99
|
+
if ( stdlib_base_is_nanf( x ) ) {
|
|
100
|
+
return 0.0f / 0.0f; // NaN
|
|
101
|
+
}
|
|
102
|
+
// Reinterpret the input value as a 32-bit integer word:
|
|
103
|
+
stdlib_base_float32_to_word( x, &uhx );
|
|
104
|
+
hx = (int32_t)uhx;
|
|
105
|
+
|
|
106
|
+
// Turn off the sign bit:
|
|
107
|
+
ix = hx & STDLIB_CONSTANT_FLOAT32_ABS_MASK;
|
|
108
|
+
|
|
109
|
+
// Case: |x| >= 1
|
|
110
|
+
if ( ix >= ONE ) {
|
|
111
|
+
// Case: |x| == 1
|
|
112
|
+
if ( ix == ONE ) {
|
|
113
|
+
// Case: x == 1
|
|
114
|
+
if ( hx > 0 ) {
|
|
115
|
+
return 0.0f; // acos(1) = 0
|
|
116
|
+
}
|
|
117
|
+
// Case: x == -1
|
|
118
|
+
return ALMOST_PI + ( 2.0f * PIO2_LO ); // acos(-1) = π
|
|
119
|
+
}
|
|
120
|
+
return 0.0f / 0.0f; // NaN as |x|>1 is outside the domain of acos
|
|
121
|
+
}
|
|
122
|
+
// Case: |x| < 0.5
|
|
123
|
+
if ( ix < ONE_HALF ) {
|
|
124
|
+
// Case: |x| < 2^-26
|
|
125
|
+
if ( ix <= SMALL ) {
|
|
126
|
+
return PIO2_HI + PIO2_LO; // acos(~0) = π/2
|
|
127
|
+
}
|
|
128
|
+
z = x * x;
|
|
129
|
+
p = z * poly_p( z );
|
|
130
|
+
q = 1.0f + ( z * QS1 );
|
|
131
|
+
r = p / q;
|
|
132
|
+
return PIO2_HI - ( x - ( PIO2_LO - ( x * r ) ) );
|
|
133
|
+
}
|
|
134
|
+
// Case: x < -0.5
|
|
135
|
+
if ( hx < 0 ) {
|
|
136
|
+
z = 0.5f * ( 1.0f + x );
|
|
137
|
+
p = z * poly_p( z );
|
|
138
|
+
q = 1.0f + ( z * QS1 );
|
|
139
|
+
s = stdlib_base_sqrtf( z );
|
|
140
|
+
r = p / q;
|
|
141
|
+
w = ( r * s ) - PIO2_LO;
|
|
142
|
+
return ALMOST_PI - ( 2.0f * ( s + w ) );
|
|
143
|
+
}
|
|
144
|
+
// Case: x > 0.5
|
|
145
|
+
z = 0.5f * ( 1.0f - x );
|
|
146
|
+
s = stdlib_base_sqrtf( z );
|
|
147
|
+
|
|
148
|
+
df = s;
|
|
149
|
+
stdlib_base_float32_to_word( df, &uidf );
|
|
150
|
+
|
|
151
|
+
idf = (int32_t)uidf;
|
|
152
|
+
stdlib_base_float32_from_word( (uint32_t)( idf&MASK_LO ), &df );
|
|
153
|
+
|
|
154
|
+
c = ( z - ( df * df ) ) / ( s + df );
|
|
155
|
+
p = z * poly_p( z );
|
|
156
|
+
q = 1.0f + ( z * QS1 );
|
|
157
|
+
r = p / q;
|
|
158
|
+
w = ( r * s ) + c;
|
|
159
|
+
return 2.0f * ( df + w );
|
|
160
|
+
}
|