Skip to content

Commit 3a5ce44

Browse files
committed
added main.c and Makefile
1 parent ac8d206 commit 3a5ce44

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
49+
# RULES #
50+
51+
#/
52+
# Removes generated files for building an add-on.
53+
#
54+
# @example
55+
# make clean-addon
56+
#/
57+
clean-addon:
58+
$(QUIET) -rm -f *.o *.node
59+
60+
.PHONY: clean-addon
61+
62+
#/
63+
# Removes generated files.
64+
#
65+
# @example
66+
# make clean
67+
#/
68+
clean: clean-addon
69+
70+
.PHONY: clean
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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/cosc.h"
20+
#include "stdlib/math/base/special/sinpi.h"
21+
#include "stdlib/math/base/special/cospi.h"
22+
#include "stdlib/math/base/assert/is_nan.h"
23+
#include "stdlib/math/base/assert/is_infinite.h"
24+
#include "stdlib/constants/float64/pi.h"
25+
26+
/**
27+
* Computes the normalized derivative of cardinal sine of a number.
28+
*
29+
* ## Method
30+
*
31+
* For \\( x \neq 0 \\), the normalized derivative of cardinal sine is calculated as
32+
*
33+
* ```tex
34+
*\operatorname{cosc}(x) = \frac{{\operatorname{cos}(\pi x)}-\frac{\operatorname{sin}(\pi x)}{\pi x}}{x}.
35+
* ```
36+
*
37+
* ## Special Cases
38+
*
39+
* ```tex
40+
* \begin{align*}
41+
* \operatorname{cosc}(0) &= 0 & \\
42+
* \operatorname{cosc}(\infty) &= 0 & \\
43+
* \operatorname{cosc}(-\infty) &= 0 & \\
44+
* \operatorname{cosc}(\mathrm{NaN}) &= \mathrm{NaN}
45+
* \end{align*}
46+
* ```
47+
*
48+
* @param x input value
49+
* @return derivative of cardinal sine
50+
*
51+
* @example
52+
* double y = stdlib_base_cosc( 0.5 );
53+
* // returns ~-1.273
54+
*/
55+
double stdlib_base_cosc( const double x ) {
56+
if ( stdlib_base_is_nan( x ) ) {
57+
return 0.0 / 0.0; // NaN
58+
}
59+
if ( stdlib_base_is_infinite( x ) ) {
60+
return 0.0;
61+
}
62+
if ( x == 0.0 ) {
63+
return 0.0;
64+
}
65+
return (stdlib_base_cospi( x ) - (stdlib_base_sinpi( x )/(STDLIB_CONSTANT_FLOAT64_PI * x))) / x;
66+
}

0 commit comments

Comments
 (0)