@stdlib/math-base-special-sinf 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 +265 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +48 -0
- package/include/stdlib/math/base/special/sinf.h +38 -0
- package/lib/index.js +49 -0
- package/lib/main.js +181 -0
- package/lib/native.js +58 -0
- package/manifest.json +96 -0
- package/package.json +81 -0
- package/src/addon.c +22 -0
- package/src/main.c +154 -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,265 @@
|
|
|
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
|
+
# Sine
|
|
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 [sine][sine] of a single-precision floating-point number (in radians).
|
|
37
|
+
|
|
38
|
+
<section class="installation">
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @stdlib/math-base-special-sinf
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
</section>
|
|
47
|
+
|
|
48
|
+
<section class="usage">
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
var sinf = require( '@stdlib/math-base-special-sinf' );
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### sinf( x )
|
|
57
|
+
|
|
58
|
+
Computes the [sine][sine] of a single-precision floating-point number (in radians).
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
var v = sinf( 0.0 );
|
|
62
|
+
// returns ~0.0
|
|
63
|
+
|
|
64
|
+
v = sinf( 3.141592653589793/2.0 );
|
|
65
|
+
// returns ~1.0
|
|
66
|
+
|
|
67
|
+
v = sinf( -3.141592653589793/6.0 );
|
|
68
|
+
// returns ~-0.5
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
</section>
|
|
72
|
+
|
|
73
|
+
<!-- /.usage -->
|
|
74
|
+
|
|
75
|
+
<section class="examples">
|
|
76
|
+
|
|
77
|
+
## Examples
|
|
78
|
+
|
|
79
|
+
<!-- eslint no-undef: "error" -->
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
83
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
84
|
+
var TWO_PI = require( '@stdlib/constants-float32-two-pi' );
|
|
85
|
+
var sinf = require( '@stdlib/math-base-special-sinf' );
|
|
86
|
+
|
|
87
|
+
var opts = {
|
|
88
|
+
'dtype': 'float32'
|
|
89
|
+
};
|
|
90
|
+
var x = uniform( 100, 0.0, TWO_PI, opts );
|
|
91
|
+
|
|
92
|
+
logEachMap( 'sinf(%0.4f) = %0.4f', x, sinf );
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
</section>
|
|
96
|
+
|
|
97
|
+
<!-- /.examples -->
|
|
98
|
+
|
|
99
|
+
<!-- C interface documentation. -->
|
|
100
|
+
|
|
101
|
+
* * *
|
|
102
|
+
|
|
103
|
+
<section class="c">
|
|
104
|
+
|
|
105
|
+
## C APIs
|
|
106
|
+
|
|
107
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
108
|
+
|
|
109
|
+
<section class="intro">
|
|
110
|
+
|
|
111
|
+
</section>
|
|
112
|
+
|
|
113
|
+
<!-- /.intro -->
|
|
114
|
+
|
|
115
|
+
<!-- C usage documentation. -->
|
|
116
|
+
|
|
117
|
+
<section class="usage">
|
|
118
|
+
|
|
119
|
+
### Usage
|
|
120
|
+
|
|
121
|
+
```c
|
|
122
|
+
#include "stdlib/math/base/special/sinf.h"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### stdlib_base_sinf( x )
|
|
126
|
+
|
|
127
|
+
Computes the [sine][sine] of a single-precision floating-point number (in radians).
|
|
128
|
+
|
|
129
|
+
```c
|
|
130
|
+
float y = stdlib_base_sinf( 3.141592653589793f / 2.0f );
|
|
131
|
+
// returns ~1.0f
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The function accepts the following arguments:
|
|
135
|
+
|
|
136
|
+
- **x**: `[in] float` input value.
|
|
137
|
+
|
|
138
|
+
```c
|
|
139
|
+
float stdlib_base_sinf( const float x );
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
</section>
|
|
143
|
+
|
|
144
|
+
<!-- /.usage -->
|
|
145
|
+
|
|
146
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
147
|
+
|
|
148
|
+
<section class="notes">
|
|
149
|
+
|
|
150
|
+
</section>
|
|
151
|
+
|
|
152
|
+
<!-- /.notes -->
|
|
153
|
+
|
|
154
|
+
<!-- C API usage examples. -->
|
|
155
|
+
|
|
156
|
+
<section class="examples">
|
|
157
|
+
|
|
158
|
+
### Examples
|
|
159
|
+
|
|
160
|
+
```c
|
|
161
|
+
#include "stdlib/math/base/special/sinf.h"
|
|
162
|
+
#include <stdio.h>
|
|
163
|
+
|
|
164
|
+
int main( void ) {
|
|
165
|
+
const float x[] = { 0.0f, 0.523f, 0.785f, 1.047f, 3.14f };
|
|
166
|
+
|
|
167
|
+
float y;
|
|
168
|
+
int i;
|
|
169
|
+
for ( i = 0; i < 5; i++ ) {
|
|
170
|
+
y = stdlib_base_sinf( x[ i ] );
|
|
171
|
+
printf( "sinf(%f) = %f\n", x[ i ], y );
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
</section>
|
|
177
|
+
|
|
178
|
+
<!-- /.examples -->
|
|
179
|
+
|
|
180
|
+
</section>
|
|
181
|
+
|
|
182
|
+
<!-- /.c -->
|
|
183
|
+
|
|
184
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
185
|
+
|
|
186
|
+
<section class="related">
|
|
187
|
+
|
|
188
|
+
</section>
|
|
189
|
+
|
|
190
|
+
<!-- /.related -->
|
|
191
|
+
|
|
192
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
<section class="main-repo" >
|
|
196
|
+
|
|
197
|
+
* * *
|
|
198
|
+
|
|
199
|
+
## Notice
|
|
200
|
+
|
|
201
|
+
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.
|
|
202
|
+
|
|
203
|
+
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].
|
|
204
|
+
|
|
205
|
+
#### Community
|
|
206
|
+
|
|
207
|
+
[![Chat][chat-image]][chat-url]
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Copyright
|
|
212
|
+
|
|
213
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
214
|
+
|
|
215
|
+
</section>
|
|
216
|
+
|
|
217
|
+
<!-- /.stdlib -->
|
|
218
|
+
|
|
219
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
220
|
+
|
|
221
|
+
<section class="links">
|
|
222
|
+
|
|
223
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-sinf.svg
|
|
224
|
+
[npm-url]: https://npmjs.org/package/@stdlib/math-base-special-sinf
|
|
225
|
+
|
|
226
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-sinf/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
227
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-sinf/actions/workflows/test.yml?query=branch:v0.1.0
|
|
228
|
+
|
|
229
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-sinf/main.svg
|
|
230
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-sinf?branch=main
|
|
231
|
+
|
|
232
|
+
<!--
|
|
233
|
+
|
|
234
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/math-base-special-sinf.svg
|
|
235
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/math-base-special-sinf/main
|
|
236
|
+
|
|
237
|
+
-->
|
|
238
|
+
|
|
239
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
240
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
241
|
+
|
|
242
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
243
|
+
|
|
244
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
245
|
+
|
|
246
|
+
[umd]: https://github.com/umdjs/umd
|
|
247
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
248
|
+
|
|
249
|
+
[deno-url]: https://github.com/stdlib-js/math-base-special-sinf/tree/deno
|
|
250
|
+
[deno-readme]: https://github.com/stdlib-js/math-base-special-sinf/blob/deno/README.md
|
|
251
|
+
[umd-url]: https://github.com/stdlib-js/math-base-special-sinf/tree/umd
|
|
252
|
+
[umd-readme]: https://github.com/stdlib-js/math-base-special-sinf/blob/umd/README.md
|
|
253
|
+
[esm-url]: https://github.com/stdlib-js/math-base-special-sinf/tree/esm
|
|
254
|
+
[esm-readme]: https://github.com/stdlib-js/math-base-special-sinf/blob/esm/README.md
|
|
255
|
+
[branches-url]: https://github.com/stdlib-js/math-base-special-sinf/blob/main/branches.md
|
|
256
|
+
|
|
257
|
+
[sine]: https://en.wikipedia.org/wiki/Sine
|
|
258
|
+
|
|
259
|
+
<!-- <related-links> -->
|
|
260
|
+
|
|
261
|
+
<!-- </related-links> -->
|
|
262
|
+
|
|
263
|
+
</section>
|
|
264
|
+
|
|
265
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";var q=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var E=q(function(p,P){
|
|
2
|
+
var t=require('@stdlib/math-base-special-kernel-cosf/dist'),u=require('@stdlib/math-base-special-kernel-sinf/dist'),c=require('@stdlib/math-base-special-rempio2f/dist'),A=require('@stdlib/number-float32-base-to-word/dist'),r=require('@stdlib/number-float64-base-to-float32/dist'),R=require('@stdlib/constants-float32-abs-mask/dist'),W=require('@stdlib/constants-float32-exponent-mask/dist'),n=require('@stdlib/constants-float64-half-pi/dist'),d=1061752794,o=1075235811,N=1081824209,T=1085271519,D=1088565717,L=964689920,O=n,_=2*n,s=3*n,I=4*n,f=[0];function S(e){var a,i,v;if(a=A(r(e))|0,i=a&R|0,i<=d)return i<L?r(e):u(e);if(i<=N)return i<=o?a>0?r(t(e-O)):r(-t(e+O)):a>0?r(u(_-e)):r(-u(_+e));if(i<=D)return i<=T?a>0?r(-t(e-s)):r(t(e+s)):a>0?r(u(e-I)):r(u(e+I));if(i>=W)return NaN;switch(v=c(r(e),f),v&3){case 0:return r(u(f[0]));case 1:return r(t(f[0]));case 2:return r(-u(f[0]));default:return r(-t(f[0]))}}P.exports=S
|
|
3
|
+
});var F=E();module.exports=F;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
/** @license Apache-2.0 */
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../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, 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/s_sinf.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'use strict';\n\n// MODULES //\n\nvar kernelCosf = require( '@stdlib/math-base-special-kernel-cosf' );\nvar kernelSinf = require( '@stdlib/math-base-special-kernel-sinf' );\nvar rempio2f = require( '@stdlib/math-base-special-rempio2f' );\nvar toWordf = require( '@stdlib/number-float32-base-to-word' );\nvar f32 = require( '@stdlib/number-float64-base-to-float32' );\nvar FLOAT32_ABS_MASK = require( '@stdlib/constants-float32-abs-mask' );\nvar FLOAT32_EXPONENT_MASK = require( '@stdlib/constants-float32-exponent-mask' );\nvar FLOAT64_HALF_PI = require( '@stdlib/constants-float64-half-pi' );\n\n\n// VARIABLES //\n\n// PI/4 = 0.7853981256484985 => 0 01111110 10010010000111111011010 => 0x3f490fda = 1061752768\nvar PIO4_WORD = 0x3f490fda|0; // asm type annotation\n\n// 3*PI/4 = 2.356194257736206 => 0 10000000 00101101100101111100011 => 0x4016cbe3 = 1075235811\nvar THREE_PIO4_WORD = 0x4016cbe3|0; // asm type annotation\n\n// 5*PI/4 = 3.9269907474517822 => 0 10000000 11110110101001111010001 => 0x407b53d1 = 1081824209\nvar FIVE_PIO4_WORD = 0x407b53d1|0; // asm type annotation\n\n// 7*PI/4 = 5.497786998748779 => 0 10000001 01011111110110111011111 => 0x40afeddf = 1085271519\nvar SEVEN_PIO4_WORD = 0x40afeddf|0; // asm type annotation\n\n// 9*PI/4 = 7.068583011627197 => 0 10000001 11000100011000111010101 => 0x40e231d5 = 1088565717\nvar NINE_PIO4_WORD = 0x40e231d5|0; // asm type annotation\n\n// 2^-12 = 0.000244140625 => 0 01110011 00000000000000000000000 => 0x39800000 = 964689920\nvar SMALL_WORD = 0x39800000|0; // asm type annotation\n\n// Small multiples of PI/2 in double-precision floating-point format:\nvar PIO2 = FLOAT64_HALF_PI; // 0x3FF921FB, 0x54442D18\nvar PI = 2.0 * FLOAT64_HALF_PI; // 0x400921FB, 0x54442D18\nvar THREE_PIO2 = 3.0 * FLOAT64_HALF_PI; // 0x4012D97C, 0x7F3321D2\nvar TWO_PI = 4.0 * FLOAT64_HALF_PI; // 0x401921FB, 0x54442D18\n\n// Array for storing the remainder element:\nvar Y = [ 0.0 ];\n\n\n// MAIN //\n\n/**\n* Computes the sine of a single-precision floating-point number (in radians).\n*\n* ## Method\n*\n* - Let \\\\(S\\\\), \\\\(C\\\\), and \\\\(T\\\\) denote the \\\\(\\sin\\\\), \\\\(\\cos\\\\), and \\\\(\\tan\\\\), respectively, on \\\\(\\[-\\pi/4, +\\pi/4\\]\\\\).\n*\n* - Reduce the argument \\\\(x\\\\) to \\\\(y = x-k\\pi/2\\\\) in \\\\(\\[-\\pi/4, +\\pi/4\\]\\\\), and let \\\\(n = k \\mod 4\\\\).\n*\n* - We have\n*\n* | n | sin(x) | cos(x) | tan(x) |\n* | - | ------ | ------ | ------ |\n* | 0 | S | C | T |\n* | 1 | C | -S | -1/T |\n* | 2 | -S | -C | T |\n* | 3 | -C | S | -1/T |\n*\n* @param {number} x - input value (in radians)\n* @returns {number} sine\n*\n* @example\n* var v = sinf( 0.0 );\n* // returns ~0.0\n*\n* @example\n* var v = sinf( 3.141592653589793/2.0 );\n* // returns ~1.0\n*\n* @example\n* var v = sinf( -3.141592653589793/6.0 );\n* // returns ~-0.5\n*\n* @example\n* var v = sinf( NaN );\n* // returns NaN\n*/\nfunction sinf( x ) {\n\tvar hx;\n\tvar ix;\n\tvar n;\n\n\thx = toWordf( f32( x ) ) |0; // asm type annotation\n\tix = (hx & FLOAT32_ABS_MASK)|0; // asm type annotation\n\n\t// Case: |x| ~<= \u03C0/4\n\tif ( ix <= PIO4_WORD ) {\n\t\t// Case: |x| < 2^-12\n\t\tif ( ix < SMALL_WORD ) {\n\t\t\treturn f32( x );\n\t\t}\n\t\treturn kernelSinf( x );\n\t}\n\t// Case: |x| ~<= 5\u03C0/4\n\tif ( ix <= FIVE_PIO4_WORD ) {\n\t\t// Case: |x| ~<= 3\u03C0/4\n\t\tif ( ix <= THREE_PIO4_WORD ) {\n\t\t\tif ( hx > 0 ) {\n\t\t\t\treturn f32( kernelCosf( x - PIO2 ) );\n\t\t\t}\n\t\t\treturn f32( -kernelCosf( x + PIO2 ) );\n\t\t}\n\t\tif ( hx > 0 ) {\n\t\t\treturn f32( kernelSinf( PI - x ) );\n\t\t}\n\t\treturn f32( -kernelSinf( PI + x ) );\n\t}\n\t// Case: |x| ~<= 9\u03C0/4\n\tif ( ix <= NINE_PIO4_WORD ) {\n\t\t// Case: |x| ~<= 7\u03C0/4\n\t\tif ( ix <= SEVEN_PIO4_WORD ) {\n\t\t\tif ( hx > 0 ) {\n\t\t\t\treturn f32( -kernelCosf( x - THREE_PIO2 ) );\n\t\t\t}\n\t\t\treturn f32( kernelCosf( x + THREE_PIO2 ) );\n\t\t}\n\t\tif ( hx > 0 ) {\n\t\t\treturn f32( kernelSinf( x - TWO_PI ) );\n\t\t}\n\t\treturn f32( kernelSinf( x + TWO_PI ) );\n\t}\n\t// Case: x is NaN or infinity\n\tif ( ix >= FLOAT32_EXPONENT_MASK ) {\n\t\treturn NaN;\n\t}\n\t// Argument reduction...\n\tn = rempio2f( f32( x ), Y );\n\tswitch ( n & 3 ) {\n\tcase 0:\n\t\treturn f32( kernelSinf( Y[ 0 ] ) );\n\tcase 1:\n\t\treturn f32( kernelCosf( Y[ 0 ] ) );\n\tcase 2:\n\t\treturn f32( -kernelSinf( Y[ 0 ] ) );\n\tdefault:\n\t\treturn f32( -kernelCosf( Y[ 0 ] ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = sinf;\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 the sine of a single-precision floating-point number (in radians).\n*\n* @module @stdlib/math-base-special-sinf\n*\n* @example\n* var sinf = require( '@stdlib/math-base-special-sinf' );\n*\n* var v = sinf( 0.0 );\n* // returns ~0.0\n*\n* v = sinf( 3.141592653589793/2.0 );\n* // returns ~1.0\n*\n* v = sinf( -3.141592653589793/6.0 );\n* // returns ~-0.5\n*\n* v = sinf( 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,cAoCA,IAAIC,EAAa,QAAS,uCAAwC,EAC9DC,EAAa,QAAS,uCAAwC,EAC9DC,EAAW,QAAS,oCAAqC,EACzDC,EAAU,QAAS,qCAAsC,EACzDC,EAAM,QAAS,wCAAyC,EACxDC,EAAmB,QAAS,oCAAqC,EACjEC,EAAwB,QAAS,yCAA0C,EAC3EC,EAAkB,QAAS,mCAAoC,EAM/DC,EAAY,WAGZC,EAAkB,WAGlBC,EAAiB,WAGjBC,EAAkB,WAGlBC,EAAiB,WAGjBC,EAAa,UAGbC,EAAOP,EACPQ,EAAK,EAAMR,EACXS,EAAa,EAAMT,EACnBU,EAAS,EAAMV,EAGfW,EAAI,CAAE,CAAI,EA0Cd,SAASC,EAAMC,EAAI,CAClB,IAAIC,EACAC,EACAC,EAMJ,GAJAF,EAAKlB,EAASC,EAAKgB,CAAE,CAAE,EAAG,EAC1BE,EAAMD,EAAKhB,EAAkB,EAGxBiB,GAAMd,EAEV,OAAKc,EAAKT,EACFT,EAAKgB,CAAE,EAERnB,EAAYmB,CAAE,EAGtB,GAAKE,GAAMZ,EAEV,OAAKY,GAAMb,EACLY,EAAK,EACFjB,EAAKJ,EAAYoB,EAAIN,CAAK,CAAE,EAE7BV,EAAK,CAACJ,EAAYoB,EAAIN,CAAK,CAAE,EAEhCO,EAAK,EACFjB,EAAKH,EAAYc,EAAKK,CAAE,CAAE,EAE3BhB,EAAK,CAACH,EAAYc,EAAKK,CAAE,CAAE,EAGnC,GAAKE,GAAMV,EAEV,OAAKU,GAAMX,EACLU,EAAK,EACFjB,EAAK,CAACJ,EAAYoB,EAAIJ,CAAW,CAAE,EAEpCZ,EAAKJ,EAAYoB,EAAIJ,CAAW,CAAE,EAErCK,EAAK,EACFjB,EAAKH,EAAYmB,EAAIH,CAAO,CAAE,EAE/Bb,EAAKH,EAAYmB,EAAIH,CAAO,CAAE,EAGtC,GAAKK,GAAMhB,EACV,MAAO,KAIR,OADAiB,EAAIrB,EAAUE,EAAKgB,CAAE,EAAGF,CAAE,EACjBK,EAAI,EAAI,CACjB,IAAK,GACJ,OAAOnB,EAAKH,EAAYiB,EAAG,CAAE,CAAE,CAAE,EAClC,IAAK,GACJ,OAAOd,EAAKJ,EAAYkB,EAAG,CAAE,CAAE,CAAE,EAClC,IAAK,GACJ,OAAOd,EAAK,CAACH,EAAYiB,EAAG,CAAE,CAAE,CAAE,EACnC,QACC,OAAOd,EAAK,CAACJ,EAAYkB,EAAG,CAAE,CAAE,CAAE,CACnC,CACD,CAKAnB,EAAO,QAAUoB,ICzIjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "kernelCosf", "kernelSinf", "rempio2f", "toWordf", "f32", "FLOAT32_ABS_MASK", "FLOAT32_EXPONENT_MASK", "FLOAT64_HALF_PI", "PIO4_WORD", "THREE_PIO4_WORD", "FIVE_PIO4_WORD", "SEVEN_PIO4_WORD", "NINE_PIO4_WORD", "SMALL_WORD", "PIO2", "PI", "THREE_PIO2", "TWO_PI", "Y", "sinf", "x", "hx", "ix", "n", "main"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
/**
|
|
22
|
+
* Computes the sine of a single-precision floating-point number (in radians).
|
|
23
|
+
*
|
|
24
|
+
* @param x - input value (in radians)
|
|
25
|
+
* @returns sine
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* var v = sinf( 0.0 );
|
|
29
|
+
* // returns ~0.0
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* var v = sinf( 3.141592653589793/2.0 );
|
|
33
|
+
* // returns ~1.0
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var v = sinf( -3.141592653589793/6.0 );
|
|
37
|
+
* // returns ~-0.5
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var v = sinf( NaN );
|
|
41
|
+
* // returns NaN
|
|
42
|
+
*/
|
|
43
|
+
declare function sinf( x: number ): number;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
// EXPORTS //
|
|
47
|
+
|
|
48
|
+
export = sinf;
|
|
@@ -0,0 +1,38 @@
|
|
|
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_SINF_H
|
|
20
|
+
#define STDLIB_MATH_BASE_SPECIAL_SINF_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 sine of a single-precision floating-point number (in radians).
|
|
31
|
+
*/
|
|
32
|
+
float stdlib_base_sinf( const float x );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_MATH_BASE_SPECIAL_SINF_H
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Compute the sine of a single-precision floating-point number (in radians).
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/math-base-special-sinf
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var sinf = require( '@stdlib/math-base-special-sinf' );
|
|
28
|
+
*
|
|
29
|
+
* var v = sinf( 0.0 );
|
|
30
|
+
* // returns ~0.0
|
|
31
|
+
*
|
|
32
|
+
* v = sinf( 3.141592653589793/2.0 );
|
|
33
|
+
* // returns ~1.0
|
|
34
|
+
*
|
|
35
|
+
* v = sinf( -3.141592653589793/6.0 );
|
|
36
|
+
* // returns ~-0.5
|
|
37
|
+
*
|
|
38
|
+
* v = sinf( NaN );
|
|
39
|
+
* // returns NaN
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
// MODULES //
|
|
43
|
+
|
|
44
|
+
var main = require( './main.js' );
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// EXPORTS //
|
|
48
|
+
|
|
49
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
* ## 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/s_sinf.c}. The implementation follows the original, but has been modified for JavaScript.
|
|
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 kernelCosf = require( '@stdlib/math-base-special-kernel-cosf' );
|
|
38
|
+
var kernelSinf = require( '@stdlib/math-base-special-kernel-sinf' );
|
|
39
|
+
var rempio2f = require( '@stdlib/math-base-special-rempio2f' );
|
|
40
|
+
var toWordf = require( '@stdlib/number-float32-base-to-word' );
|
|
41
|
+
var f32 = require( '@stdlib/number-float64-base-to-float32' );
|
|
42
|
+
var FLOAT32_ABS_MASK = require( '@stdlib/constants-float32-abs-mask' );
|
|
43
|
+
var FLOAT32_EXPONENT_MASK = require( '@stdlib/constants-float32-exponent-mask' );
|
|
44
|
+
var FLOAT64_HALF_PI = require( '@stdlib/constants-float64-half-pi' );
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// VARIABLES //
|
|
48
|
+
|
|
49
|
+
// PI/4 = 0.7853981256484985 => 0 01111110 10010010000111111011010 => 0x3f490fda = 1061752768
|
|
50
|
+
var PIO4_WORD = 0x3f490fda|0; // asm type annotation
|
|
51
|
+
|
|
52
|
+
// 3*PI/4 = 2.356194257736206 => 0 10000000 00101101100101111100011 => 0x4016cbe3 = 1075235811
|
|
53
|
+
var THREE_PIO4_WORD = 0x4016cbe3|0; // asm type annotation
|
|
54
|
+
|
|
55
|
+
// 5*PI/4 = 3.9269907474517822 => 0 10000000 11110110101001111010001 => 0x407b53d1 = 1081824209
|
|
56
|
+
var FIVE_PIO4_WORD = 0x407b53d1|0; // asm type annotation
|
|
57
|
+
|
|
58
|
+
// 7*PI/4 = 5.497786998748779 => 0 10000001 01011111110110111011111 => 0x40afeddf = 1085271519
|
|
59
|
+
var SEVEN_PIO4_WORD = 0x40afeddf|0; // asm type annotation
|
|
60
|
+
|
|
61
|
+
// 9*PI/4 = 7.068583011627197 => 0 10000001 11000100011000111010101 => 0x40e231d5 = 1088565717
|
|
62
|
+
var NINE_PIO4_WORD = 0x40e231d5|0; // asm type annotation
|
|
63
|
+
|
|
64
|
+
// 2^-12 = 0.000244140625 => 0 01110011 00000000000000000000000 => 0x39800000 = 964689920
|
|
65
|
+
var SMALL_WORD = 0x39800000|0; // asm type annotation
|
|
66
|
+
|
|
67
|
+
// Small multiples of PI/2 in double-precision floating-point format:
|
|
68
|
+
var PIO2 = FLOAT64_HALF_PI; // 0x3FF921FB, 0x54442D18
|
|
69
|
+
var PI = 2.0 * FLOAT64_HALF_PI; // 0x400921FB, 0x54442D18
|
|
70
|
+
var THREE_PIO2 = 3.0 * FLOAT64_HALF_PI; // 0x4012D97C, 0x7F3321D2
|
|
71
|
+
var TWO_PI = 4.0 * FLOAT64_HALF_PI; // 0x401921FB, 0x54442D18
|
|
72
|
+
|
|
73
|
+
// Array for storing the remainder element:
|
|
74
|
+
var Y = [ 0.0 ];
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
// MAIN //
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Computes the sine of a single-precision floating-point number (in radians).
|
|
81
|
+
*
|
|
82
|
+
* ## Method
|
|
83
|
+
*
|
|
84
|
+
* - Let \\(S\\), \\(C\\), and \\(T\\) denote the \\(\sin\\), \\(\cos\\), and \\(\tan\\), respectively, on \\(\[-\pi/4, +\pi/4\]\\).
|
|
85
|
+
*
|
|
86
|
+
* - Reduce the argument \\(x\\) to \\(y = x-k\pi/2\\) in \\(\[-\pi/4, +\pi/4\]\\), and let \\(n = k \mod 4\\).
|
|
87
|
+
*
|
|
88
|
+
* - We have
|
|
89
|
+
*
|
|
90
|
+
* | n | sin(x) | cos(x) | tan(x) |
|
|
91
|
+
* | - | ------ | ------ | ------ |
|
|
92
|
+
* | 0 | S | C | T |
|
|
93
|
+
* | 1 | C | -S | -1/T |
|
|
94
|
+
* | 2 | -S | -C | T |
|
|
95
|
+
* | 3 | -C | S | -1/T |
|
|
96
|
+
*
|
|
97
|
+
* @param {number} x - input value (in radians)
|
|
98
|
+
* @returns {number} sine
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* var v = sinf( 0.0 );
|
|
102
|
+
* // returns ~0.0
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* var v = sinf( 3.141592653589793/2.0 );
|
|
106
|
+
* // returns ~1.0
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* var v = sinf( -3.141592653589793/6.0 );
|
|
110
|
+
* // returns ~-0.5
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* var v = sinf( NaN );
|
|
114
|
+
* // returns NaN
|
|
115
|
+
*/
|
|
116
|
+
function sinf( x ) {
|
|
117
|
+
var hx;
|
|
118
|
+
var ix;
|
|
119
|
+
var n;
|
|
120
|
+
|
|
121
|
+
hx = toWordf( f32( x ) ) |0; // asm type annotation
|
|
122
|
+
ix = (hx & FLOAT32_ABS_MASK)|0; // asm type annotation
|
|
123
|
+
|
|
124
|
+
// Case: |x| ~<= π/4
|
|
125
|
+
if ( ix <= PIO4_WORD ) {
|
|
126
|
+
// Case: |x| < 2^-12
|
|
127
|
+
if ( ix < SMALL_WORD ) {
|
|
128
|
+
return f32( x );
|
|
129
|
+
}
|
|
130
|
+
return kernelSinf( x );
|
|
131
|
+
}
|
|
132
|
+
// Case: |x| ~<= 5π/4
|
|
133
|
+
if ( ix <= FIVE_PIO4_WORD ) {
|
|
134
|
+
// Case: |x| ~<= 3π/4
|
|
135
|
+
if ( ix <= THREE_PIO4_WORD ) {
|
|
136
|
+
if ( hx > 0 ) {
|
|
137
|
+
return f32( kernelCosf( x - PIO2 ) );
|
|
138
|
+
}
|
|
139
|
+
return f32( -kernelCosf( x + PIO2 ) );
|
|
140
|
+
}
|
|
141
|
+
if ( hx > 0 ) {
|
|
142
|
+
return f32( kernelSinf( PI - x ) );
|
|
143
|
+
}
|
|
144
|
+
return f32( -kernelSinf( PI + x ) );
|
|
145
|
+
}
|
|
146
|
+
// Case: |x| ~<= 9π/4
|
|
147
|
+
if ( ix <= NINE_PIO4_WORD ) {
|
|
148
|
+
// Case: |x| ~<= 7π/4
|
|
149
|
+
if ( ix <= SEVEN_PIO4_WORD ) {
|
|
150
|
+
if ( hx > 0 ) {
|
|
151
|
+
return f32( -kernelCosf( x - THREE_PIO2 ) );
|
|
152
|
+
}
|
|
153
|
+
return f32( kernelCosf( x + THREE_PIO2 ) );
|
|
154
|
+
}
|
|
155
|
+
if ( hx > 0 ) {
|
|
156
|
+
return f32( kernelSinf( x - TWO_PI ) );
|
|
157
|
+
}
|
|
158
|
+
return f32( kernelSinf( x + TWO_PI ) );
|
|
159
|
+
}
|
|
160
|
+
// Case: x is NaN or infinity
|
|
161
|
+
if ( ix >= FLOAT32_EXPONENT_MASK ) {
|
|
162
|
+
return NaN;
|
|
163
|
+
}
|
|
164
|
+
// Argument reduction...
|
|
165
|
+
n = rempio2f( f32( x ), Y );
|
|
166
|
+
switch ( n & 3 ) {
|
|
167
|
+
case 0:
|
|
168
|
+
return f32( kernelSinf( Y[ 0 ] ) );
|
|
169
|
+
case 1:
|
|
170
|
+
return f32( kernelCosf( Y[ 0 ] ) );
|
|
171
|
+
case 2:
|
|
172
|
+
return f32( -kernelSinf( Y[ 0 ] ) );
|
|
173
|
+
default:
|
|
174
|
+
return f32( -kernelCosf( Y[ 0 ] ) );
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
// EXPORTS //
|
|
180
|
+
|
|
181
|
+
module.exports = sinf;
|
package/lib/native.js
ADDED
|
@@ -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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var addon = require( './../src/addon.node' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Computes the sine of a single-precision floating-point number (in radians).
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value (in radians)
|
|
33
|
+
* @returns {number} sine
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var v = sinf( 0.0 );
|
|
37
|
+
* // returns ~0.0
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var v = sinf( 3.141592653589793/2.0 );
|
|
41
|
+
* // returns ~1.0
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var v = sinf( -3.141592653589793/6.0 );
|
|
45
|
+
* // returns ~-0.5
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var v = sinf( NaN );
|
|
49
|
+
* // returns NaN
|
|
50
|
+
*/
|
|
51
|
+
function sinf( x ) {
|
|
52
|
+
return addon( x );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = sinf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
"-lm"
|
|
38
|
+
],
|
|
39
|
+
"libpath": [],
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"@stdlib/math-base-napi-unary",
|
|
42
|
+
"@stdlib/number-float32-base-to-word",
|
|
43
|
+
"@stdlib/constants-float64-half-pi",
|
|
44
|
+
"@stdlib/constants-float32-abs-mask",
|
|
45
|
+
"@stdlib/constants-float32-exponent-mask",
|
|
46
|
+
"@stdlib/math-base-special-kernel-cosf",
|
|
47
|
+
"@stdlib/math-base-special-kernel-sinf",
|
|
48
|
+
"@stdlib/math-base-special-rempio2f"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"task": "benchmark",
|
|
53
|
+
"src": [
|
|
54
|
+
"./src/main.c"
|
|
55
|
+
],
|
|
56
|
+
"include": [
|
|
57
|
+
"./include"
|
|
58
|
+
],
|
|
59
|
+
"libraries": [
|
|
60
|
+
"-lm"
|
|
61
|
+
],
|
|
62
|
+
"libpath": [],
|
|
63
|
+
"dependencies": [
|
|
64
|
+
"@stdlib/number-float32-base-to-word",
|
|
65
|
+
"@stdlib/constants-float64-half-pi",
|
|
66
|
+
"@stdlib/constants-float32-abs-mask",
|
|
67
|
+
"@stdlib/constants-float32-exponent-mask",
|
|
68
|
+
"@stdlib/math-base-special-kernel-cosf",
|
|
69
|
+
"@stdlib/math-base-special-kernel-sinf",
|
|
70
|
+
"@stdlib/math-base-special-rempio2f"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"task": "examples",
|
|
75
|
+
"src": [
|
|
76
|
+
"./src/main.c"
|
|
77
|
+
],
|
|
78
|
+
"include": [
|
|
79
|
+
"./include"
|
|
80
|
+
],
|
|
81
|
+
"libraries": [
|
|
82
|
+
"-lm"
|
|
83
|
+
],
|
|
84
|
+
"libpath": [],
|
|
85
|
+
"dependencies": [
|
|
86
|
+
"@stdlib/number-float32-base-to-word",
|
|
87
|
+
"@stdlib/constants-float64-half-pi",
|
|
88
|
+
"@stdlib/constants-float32-abs-mask",
|
|
89
|
+
"@stdlib/constants-float32-exponent-mask",
|
|
90
|
+
"@stdlib/math-base-special-kernel-cosf",
|
|
91
|
+
"@stdlib/math-base-special-kernel-sinf",
|
|
92
|
+
"@stdlib/math-base-special-rempio2f"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/math-base-special-sinf",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Compute the sine of a single-precision floating-point number (in radians).",
|
|
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
|
+
"src": "./src",
|
|
23
|
+
"dist": "./dist"
|
|
24
|
+
},
|
|
25
|
+
"types": "./docs/types",
|
|
26
|
+
"scripts": {},
|
|
27
|
+
"homepage": "https://stdlib.io",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git://github.com/stdlib-js/math-base-special-sinf.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@stdlib/constants-float32-abs-mask": "^0.2.2",
|
|
37
|
+
"@stdlib/constants-float32-exponent-mask": "^0.2.2",
|
|
38
|
+
"@stdlib/constants-float64-half-pi": "^0.2.2",
|
|
39
|
+
"@stdlib/math-base-napi-unary": "^0.2.5",
|
|
40
|
+
"@stdlib/math-base-special-kernel-cosf": "github:stdlib-js/math-base-special-kernel-cosf#main",
|
|
41
|
+
"@stdlib/math-base-special-kernel-sinf": "github:stdlib-js/math-base-special-kernel-sinf#main",
|
|
42
|
+
"@stdlib/math-base-special-rempio2f": "github:stdlib-js/math-base-special-rempio2f#main",
|
|
43
|
+
"@stdlib/number-float32-base-to-word": "^0.2.2",
|
|
44
|
+
"@stdlib/number-float64-base-to-float32": "^0.2.2",
|
|
45
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=0.10.0",
|
|
50
|
+
"npm": ">2.7.0"
|
|
51
|
+
},
|
|
52
|
+
"os": [
|
|
53
|
+
"aix",
|
|
54
|
+
"darwin",
|
|
55
|
+
"freebsd",
|
|
56
|
+
"linux",
|
|
57
|
+
"macos",
|
|
58
|
+
"openbsd",
|
|
59
|
+
"sunos",
|
|
60
|
+
"win32",
|
|
61
|
+
"windows"
|
|
62
|
+
],
|
|
63
|
+
"keywords": [
|
|
64
|
+
"stdlib",
|
|
65
|
+
"stdmath",
|
|
66
|
+
"mathematics",
|
|
67
|
+
"math",
|
|
68
|
+
"math.sin",
|
|
69
|
+
"sin",
|
|
70
|
+
"sinf",
|
|
71
|
+
"sine",
|
|
72
|
+
"trig",
|
|
73
|
+
"trigonometry",
|
|
74
|
+
"radians",
|
|
75
|
+
"angle"
|
|
76
|
+
],
|
|
77
|
+
"funding": {
|
|
78
|
+
"type": "opencollective",
|
|
79
|
+
"url": "https://opencollective.com/stdlib"
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
#include "stdlib/math/base/special/sinf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/unary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_sinf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
* ## 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/s_sinf.c}. The implementation follows the original, but has been modified according to stdlib 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/sinf.h"
|
|
34
|
+
#include "stdlib/math/base/special/kernel_cosf.h"
|
|
35
|
+
#include "stdlib/math/base/special/kernel_sinf.h"
|
|
36
|
+
#include "stdlib/math/base/special/rempio2f.h"
|
|
37
|
+
#include "stdlib/constants/float64/half_pi.h"
|
|
38
|
+
#include "stdlib/constants/float32/abs_mask.h"
|
|
39
|
+
#include "stdlib/constants/float32/exponent_mask.h"
|
|
40
|
+
#include "stdlib/number/float32/base/to_word.h"
|
|
41
|
+
#include <stdint.h>
|
|
42
|
+
|
|
43
|
+
// PI/4 = 0.7853981256484985 => 0 01111110 10010010000111111011010 => 0x3f490fda = 1061752768
|
|
44
|
+
static const int32_t PIO4_WORD = 0x3f490fda;
|
|
45
|
+
|
|
46
|
+
// 3*PI/4 = 2.356194257736206 => 0 10000000 00101101100101111100011 => 0x4016cbe3 = 1075235811
|
|
47
|
+
static const int32_t THREE_PIO4_WORD = 0x4016cbe3;
|
|
48
|
+
|
|
49
|
+
// 5*PI/4 = 3.9269907474517822 => 0 10000000 11110110101001111010001 => 0x407b53d1 = 1081824209
|
|
50
|
+
static const int32_t FIVE_PIO4_WORD = 0x407b53d1;
|
|
51
|
+
|
|
52
|
+
// 7*PI/4 = 5.497786998748779 => 0 10000001 01011111110110111011111 => 0x40afeddf = 1085271519
|
|
53
|
+
static const int32_t SEVEN_PIO4_WORD = 0x40afeddf;
|
|
54
|
+
|
|
55
|
+
// 9*PI/4 = 7.068583011627197 => 0 10000001 11000100011000111010101 => 0x40e231d5 = 1088565717
|
|
56
|
+
static const int32_t NINE_PIO4_WORD = 0x40e231d5;
|
|
57
|
+
|
|
58
|
+
// 2^-12 = 0.000244140625 => 0 01110011 00000000000000000000000 => 0x39800000 = 964689920
|
|
59
|
+
static const int32_t SMALL_WORD = 0x39800000;
|
|
60
|
+
|
|
61
|
+
// Small multiples of PI/2 in double-precision floating-point format:
|
|
62
|
+
static const double PIO2 = STDLIB_CONSTANT_FLOAT64_HALF_PI; // 0x3FF921FB, 0x54442D18
|
|
63
|
+
static const double PI = 2.0 * STDLIB_CONSTANT_FLOAT64_HALF_PI; // 0x400921FB, 0x54442D18
|
|
64
|
+
static const double THREE_PIO2 = 3.0 * STDLIB_CONSTANT_FLOAT64_HALF_PI; // 0x4012D97C, 0x7F3321D2
|
|
65
|
+
static const double TWO_PI = 4.0 * STDLIB_CONSTANT_FLOAT64_HALF_PI; // 0x401921FB, 0x54442D18
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Computes the sine of a single-precision floating-point number (in radians).
|
|
69
|
+
*
|
|
70
|
+
* ## Method
|
|
71
|
+
*
|
|
72
|
+
* - Let \\(S\\), \\(C\\), and \\(T\\) denote the \\(\sin\\), \\(\cos\\), and \\(\tan\\), respectively, on \\(\[-\pi/4, +\pi/4\]\\).
|
|
73
|
+
*
|
|
74
|
+
* - Reduce the argument \\(x\\) to \\(y = x-k\pi/2\\) in \\(\[-\pi/4, +\pi/4\]\\), and let \\(n = k \mod 4\\).
|
|
75
|
+
*
|
|
76
|
+
* - We have
|
|
77
|
+
*
|
|
78
|
+
* | n | sin(x) | cos(x) | tan(x) |
|
|
79
|
+
* | - | ------ | ------ | ------ |
|
|
80
|
+
* | 0 | S | C | T |
|
|
81
|
+
* | 1 | C | -S | -1/T |
|
|
82
|
+
* | 2 | -S | -C | T |
|
|
83
|
+
* | 3 | -C | S | -1/T |
|
|
84
|
+
*
|
|
85
|
+
* @param x input value (in radians)
|
|
86
|
+
* @return sine
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* float y = stdlib_base_sinf( 3.141592653589793f / 2.0f );
|
|
90
|
+
* // returns 1.0f
|
|
91
|
+
*/
|
|
92
|
+
float stdlib_base_sinf( const float x ) {
|
|
93
|
+
uint32_t uix;
|
|
94
|
+
int32_t ix;
|
|
95
|
+
int32_t n;
|
|
96
|
+
double y;
|
|
97
|
+
|
|
98
|
+
stdlib_base_float32_to_word( x, &uix );
|
|
99
|
+
ix = (int32_t)uix;
|
|
100
|
+
ix &= STDLIB_CONSTANT_FLOAT32_ABS_MASK;
|
|
101
|
+
|
|
102
|
+
// Case: |x| ~<= π/4
|
|
103
|
+
if ( ix <= PIO4_WORD ) {
|
|
104
|
+
// Case: |x| < 2^-12
|
|
105
|
+
if ( ix < SMALL_WORD ) {
|
|
106
|
+
return x;
|
|
107
|
+
}
|
|
108
|
+
return stdlib_base_kernel_sinf( (double)x );
|
|
109
|
+
}
|
|
110
|
+
// Case: |x| ~<= 5π/4
|
|
111
|
+
if ( ix <= FIVE_PIO4_WORD ) {
|
|
112
|
+
// Case: |x| ~<= 3π/4
|
|
113
|
+
if ( ix <= THREE_PIO4_WORD ) {
|
|
114
|
+
if ( (int32_t)uix > 0 ) {
|
|
115
|
+
return stdlib_base_kernel_cosf( (double)x - PIO2 );
|
|
116
|
+
}
|
|
117
|
+
return -stdlib_base_kernel_cosf( (double)x + PIO2 );
|
|
118
|
+
}
|
|
119
|
+
if ( (int32_t)uix > 0 ) {
|
|
120
|
+
return stdlib_base_kernel_sinf( PI - (double)x );
|
|
121
|
+
}
|
|
122
|
+
return -stdlib_base_kernel_sinf( PI + (double)x );
|
|
123
|
+
}
|
|
124
|
+
// Case: |x| ~<= 9π/4
|
|
125
|
+
if ( ix <= NINE_PIO4_WORD ) {
|
|
126
|
+
// Case: |x| ~<= 7π/4
|
|
127
|
+
if ( ix <= SEVEN_PIO4_WORD ) {
|
|
128
|
+
if ( (int32_t)uix > 0 ) {
|
|
129
|
+
return -stdlib_base_kernel_cosf( (double)x - THREE_PIO2 );
|
|
130
|
+
}
|
|
131
|
+
return stdlib_base_kernel_cosf( (double)x + THREE_PIO2 );
|
|
132
|
+
}
|
|
133
|
+
if ( (int32_t)uix > 0 ) {
|
|
134
|
+
return stdlib_base_kernel_sinf( (double)x - TWO_PI );
|
|
135
|
+
}
|
|
136
|
+
return stdlib_base_kernel_sinf( (double)x + TWO_PI );
|
|
137
|
+
}
|
|
138
|
+
// Case: x is NaN or infinity
|
|
139
|
+
if ( ix >= STDLIB_CONSTANT_FLOAT32_EXPONENT_MASK ) {
|
|
140
|
+
return 0.0f / 0.0f; // NaN
|
|
141
|
+
}
|
|
142
|
+
// Argument reduction...
|
|
143
|
+
n = stdlib_base_rempio2f( x, &y );
|
|
144
|
+
switch ( n & 3 ) {
|
|
145
|
+
case 0:
|
|
146
|
+
return stdlib_base_kernel_sinf( y );
|
|
147
|
+
case 1:
|
|
148
|
+
return stdlib_base_kernel_cosf( y );
|
|
149
|
+
case 2:
|
|
150
|
+
return -stdlib_base_kernel_sinf( y );
|
|
151
|
+
default:
|
|
152
|
+
return -stdlib_base_kernel_cosf( y );
|
|
153
|
+
}
|
|
154
|
+
}
|