Skip to content

Commit 3ddc39e

Browse files
author
aayush0325
committed
feat: c files added
1 parent 37f2cc8 commit 3ddc39e

File tree

4 files changed

+216
-0
lines changed

4 files changed

+216
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_NONFIBONACCIF_H
20+
#define STDLIB_MATH_BASE_SPECIAL_NONFIBONACCIF_H
21+
22+
#include <stdint.h>
23+
24+
/*
25+
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
26+
*/
27+
#ifdef __cplusplus
28+
extern "C"
29+
{
30+
#endif
31+
32+
/**
33+
* Computes the nth non-Fibonacci number in single-precision floating-point format.
34+
*/
35+
float stdlib_base_nonfibonaccif( const int32_t n );
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
41+
#endif // !STDLIB_MATH_BASE_SPECIAL_NONFIBONACCIF_H
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/nonfibonaccif.h"
20+
#include "stdlib/math/base/napi/unary.h"
21+
22+
// cppcheck-suppress shadowFunction
23+
STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_nonfibonaccif )
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 <stdint.h>
20+
21+
#include "stdlib/math/base/special/nonfibonaccif.h"
22+
#include "stdlib/constants/float32/nan.h"
23+
#include "stdlib/constants/float32/phi.h"
24+
#include "stdlib/constants/float32/pinf.h"
25+
#include "stdlib/math/base/assert/is_integerf.h"
26+
#include "stdlib/math/base/assert/is_nanf.h"
27+
#include "stdlib/math/base/special/floorf.h"
28+
#include "stdlib/math/base/special/lnf.h"
29+
30+
#define SQRT5 2.23606797749979
31+
#define LN_PHI 0.48121182506
32+
33+
/**
34+
* Computes the nth non-Fibonacci number in single-precision floating-point format.
35+
*
36+
* @param x input value
37+
* @return output value
38+
*
39+
* @example
40+
* float y = stdlib_base_nonfibonaccif( 2 );
41+
* // returns 6.0f
42+
*
43+
* @example
44+
* float y = stdlib_base_nonfibonaccif( 1 );
45+
* // returns 4.0f
46+
*
47+
* @example
48+
* float y = stdlib_base_nonfibonaccif( 3 );
49+
* // returns 7.0f
50+
*
51+
* @example
52+
* float y = stdlib_base_nonfibonaccif( NaN );
53+
* // returns NaN
54+
*
55+
* @example
56+
* float y = stdlib_base_nonfibonaccif( 3.14 );
57+
* // returns NaN
58+
*
59+
* @example
60+
* float y = stdlib_base_nonfibonaccif( -1 );
61+
* // returns NaN
62+
*/
63+
float stdlib_base_nonfibonaccif( const int32_t n ) {
64+
float a;
65+
float b;
66+
int32_t mut_n = n;
67+
68+
if (
69+
stdlib_base_is_nanf( n ) ||
70+
!stdlib_base_is_integerf( n ) ||
71+
n < 1.0f ||
72+
n == STDLIB_CONSTANT_FLOAT32_PINF
73+
) {
74+
return STDLIB_CONSTANT_FLOAT32_NAN;
75+
}
76+
77+
mut_n += 1;
78+
a = stdlib_base_lnf( mut_n * SQRT5 ) / LN_PHI;
79+
b = stdlib_base_lnf( (SQRT5 * ( mut_n + a ) ) - 5.0f + ( 3.0f / mut_n ) ) / LN_PHI;
80+
81+
return stdlib_base_floorf( mut_n + b - 2.0f );
82+
}

0 commit comments

Comments
 (0)