Skip to content

Commit 224d7f2

Browse files
feat: docs & examples added
1 parent 4a15e2e commit 224d7f2

File tree

7 files changed

+375
-1
lines changed

7 files changed

+375
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
{{alias}}( y, x )
3+
Computes the angle in the plane (in radians) between the positive x-axis and
4+
the ray from (0,0) to the point (x,y).
5+
6+
Parameters
7+
----------
8+
y: number
9+
Coordinate along y-axis.
10+
11+
x: number
12+
Coordinate along x-axis.
13+
14+
Returns
15+
-------
16+
out: number
17+
Angle (in radians).
18+
19+
Examples
20+
--------
21+
> var v = {{alias}}( 2.0, 2.0 )
22+
~0.785
23+
> v = {{alias}}( 6.0, 2.0 )
24+
~1.249
25+
> v = {{alias}}( -1.0, -1.0 )
26+
~-2.356
27+
> v = {{alias}}( 3.0, 0.0 )
28+
~1.571
29+
> v = {{alias}}( -2.0, 0.0 )
30+
~-1.571
31+
> v = {{alias}}( 0.0, 0.0 )
32+
0.0
33+
> v = {{alias}}( 3.0, NaN )
34+
NaN
35+
> v = {{alias}}( NaN, 2.0 )
36+
NaN
37+
38+
See Also
39+
--------
40+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 angle in the plane (in radians) between the positive x-axis and the ray from `(0,0)` to the point `(x,y)`.
23+
*
24+
* @param y - `y` coordinate
25+
* @param x - `x` coordinate
26+
* @returns angle (in radians)
27+
*
28+
* @example
29+
* var v = atan2f( 2.0, 2.0 ); // => atanf(1.0)
30+
* // returns ~0.785
31+
*
32+
* @example
33+
* var v = atan2f( 6.0, 2.0 ); // => atanf(3.0)
34+
* // returns ~1.249
35+
*
36+
* @example
37+
* var v = atan2f( -1.0, -1.0 ); // => atanf(1.0) - π
38+
* // returns ~-2.356
39+
*
40+
* @example
41+
* var v = atan2f( 3.0, 0.0 ); // => π/2
42+
* // returns ~1.571
43+
*
44+
* @example
45+
* var v = atan2f( -2.0, 0.0 ); // => -π/2
46+
* // returns ~-1.571
47+
*
48+
* @example
49+
* var v = atan2f( 0.0, 0.0 );
50+
* // returns 0.0
51+
*
52+
* @example
53+
* var v = atan2f( 3.0, NaN );
54+
* // returns NaN
55+
*
56+
* @example
57+
* var v = atan2f( NaN, 2.0 );
58+
* // returns NaN
59+
*/
60+
declare function atan2f( y: number, x: number ): number;
61+
62+
63+
// EXPORTS //
64+
65+
export = atan2f;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
import atan2f = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number...
25+
{
26+
atan2f( 8, 2 ); // $ExpectType number
27+
}
28+
29+
// The compiler throws an error if the function is provided values other than two numbers...
30+
{
31+
atan2f( true, 3 ); // $ExpectError
32+
atan2f( false, 2 ); // $ExpectError
33+
atan2f( '5', 1 ); // $ExpectError
34+
atan2f( [], 1 ); // $ExpectError
35+
atan2f( {}, 2 ); // $ExpectError
36+
atan2f( ( x: number ): number => x, 2 ); // $ExpectError
37+
38+
atan2f( 9, true ); // $ExpectError
39+
atan2f( 9, false ); // $ExpectError
40+
atan2f( 5, '5' ); // $ExpectError
41+
atan2f( 8, [] ); // $ExpectError
42+
atan2f( 9, {} ); // $ExpectError
43+
atan2f( 8, ( x: number ): number => x ); // $ExpectError
44+
45+
atan2f( [], true ); // $ExpectError
46+
atan2f( {}, false ); // $ExpectError
47+
atan2f( false, '5' ); // $ExpectError
48+
atan2f( {}, [] ); // $ExpectError
49+
atan2f( '5', ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The compiler throws an error if the function is provided insufficient arguments...
53+
{
54+
atan2f(); // $ExpectError
55+
atan2f( 3 ); // $ExpectError
56+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
# VARIABLES #
20+
21+
ifndef VERBOSE
22+
QUIET := @
23+
else
24+
QUIET :=
25+
endif
26+
27+
# Determine the OS ([1][1], [2][2]).
28+
#
29+
# [1]: https://en.wikipedia.org/wiki/Uname#Examples
30+
# [2]: http://stackoverflow.com/a/27776822/2225624
31+
OS ?= $(shell uname)
32+
ifneq (, $(findstring MINGW,$(OS)))
33+
OS := WINNT
34+
else
35+
ifneq (, $(findstring MSYS,$(OS)))
36+
OS := WINNT
37+
else
38+
ifneq (, $(findstring CYGWIN,$(OS)))
39+
OS := WINNT
40+
else
41+
ifneq (, $(findstring Windows_NT,$(OS)))
42+
OS := WINNT
43+
endif
44+
endif
45+
endif
46+
endif
47+
48+
# Define the program used for compiling C source files:
49+
ifdef C_COMPILER
50+
CC := $(C_COMPILER)
51+
else
52+
CC := gcc
53+
endif
54+
55+
# Define the command-line options when compiling C files:
56+
CFLAGS ?= \
57+
-std=c99 \
58+
-O3 \
59+
-Wall \
60+
-pedantic
61+
62+
# Determine whether to generate position independent code ([1][1], [2][2]).
63+
#
64+
# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options
65+
# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option
66+
ifeq ($(OS), WINNT)
67+
fPIC ?=
68+
else
69+
fPIC ?= -fPIC
70+
endif
71+
72+
# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`):
73+
INCLUDE ?=
74+
75+
# List of source files:
76+
SOURCE_FILES ?=
77+
78+
# List of libraries (e.g., `-lopenblas -lpthread`):
79+
LIBRARIES ?=
80+
81+
# List of library paths (e.g., `-L /foo/bar -L /beep/boop`):
82+
LIBPATH ?=
83+
84+
# List of C targets:
85+
c_targets := example.out
86+
87+
88+
# RULES #
89+
90+
#/
91+
# Compiles source files.
92+
#
93+
# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`)
94+
# @param {string} [CFLAGS] - C compiler options
95+
# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
96+
# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`)
97+
# @param {string} [SOURCE_FILES] - list of source files
98+
# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`)
99+
# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`)
100+
#
101+
# @example
102+
# make
103+
#
104+
# @example
105+
# make all
106+
#/
107+
all: $(c_targets)
108+
109+
.PHONY: all
110+
111+
#/
112+
# Compiles C source files.
113+
#
114+
# @private
115+
# @param {string} CC - C compiler (e.g., `gcc`)
116+
# @param {string} CFLAGS - C compiler options
117+
# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`)
118+
# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`)
119+
# @param {string} SOURCE_FILES - list of source files
120+
# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`)
121+
# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`)
122+
#/
123+
$(c_targets): %.out: %.c
124+
$(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES)
125+
126+
#/
127+
# Runs compiled examples.
128+
#
129+
# @example
130+
# make run
131+
#/
132+
run: $(c_targets)
133+
$(QUIET) ./$<
134+
135+
.PHONY: run
136+
137+
#/
138+
# Removes generated files.
139+
#
140+
# @example
141+
# make clean
142+
#/
143+
clean:
144+
$(QUIET) -rm -f *.o *.out
145+
146+
.PHONY: clean
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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/atan2f.h"
20+
#include <stdlib.h>
21+
#include <stdio.h>
22+
23+
int main( void ) {
24+
float y;
25+
float x;
26+
float v;
27+
int i;
28+
for ( i = 0; i < 100; i++ ) {
29+
y = ( ( (float)rand() / (float)RAND_MAX ) * 100.0f );
30+
x = ( ( (float)rand() / (float)RAND_MAX ) * 100.0f );
31+
v = stdlib_base_atan2f( y, x );
32+
printf( "atan2f(%f, %f) = %f\n", y, x, v );
33+
}
34+
return 0;
35+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
var randu = require( '@stdlib/random/base/randu' );
22+
var atan2f = require( './../lib' );
23+
24+
var x;
25+
var y;
26+
var i;
27+
28+
for ( i = 0; i < 100; i++ ) {
29+
y = randu() * 100.0;
30+
x = randu() * 100.0;
31+
console.log( 'y: %d, \t x: %d, \t atan2(y,x): %d', y.toFixed( 4 ), x.toFixed( 4 ), atan2f( y, x ).toFixed( 4 ) );
32+
}

lib/node_modules/@stdlib/math/base/special/atan2f/test/fixtures/julia/runner.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ julia> gen( x, y, \"data.json\" );
4040
function gen( x, y, name )
4141
z = Array{Float64}( undef, length(x) );
4242
for i in eachindex(x)
43-
z[ i ] = atan2.( y[i], x[i] );
43+
z[ i ] = atan2f.( y[i], x[i] );
4444
end
4545

4646
# Store data to be written to file as a collection:

0 commit comments

Comments
 (0)