Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 10, 2024
1 parent ba967a5 commit 3704ecf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4464,6 +4464,7 @@ A total of 26 people contributed to this release. Thank you to the following con

<details>

- [`ced30b0`](https://github.com/stdlib-js/stdlib/commit/ced30b0e285117ad5bcdf6cc940329aadc826e21) - **refactor:** use constant packages and remove unused include [(#2355)](https://github.com/stdlib-js/stdlib/pull/2355) _(by Gunj Joshi)_
- [`343da6f`](https://github.com/stdlib-js/stdlib/commit/343da6faa466294331be4befd603fde2faa83503) - **feat:** add C implementation for `math/base/special/cos` _(by Gunj Joshi, Philipp Burckhardt)_
- [`a985cc2`](https://github.com/stdlib-js/stdlib/commit/a985cc224aa74759783c5c4d9577769a36ed818f) - **feat:** add `math/base/special/nanmin` _(by Ridam Garg, RidamGarg, stdlib-bot, Philipp Burckhardt)_
- [`ddf4bdb`](https://github.com/stdlib-js/stdlib/commit/ddf4bdb3e92d8817fa57bdefe8d375f40b4abdfa) - **feat:** add C implementation for `math/base/special/sin` _(by Gunj Joshi, Philipp Burckhardt)_
Expand Down
2 changes: 0 additions & 2 deletions base/special/cos/include/stdlib/math/base/special/cos.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_COS_H
#define STDLIB_MATH_BASE_SPECIAL_COS_H

#include <stdint.h>

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand Down
12 changes: 4 additions & 8 deletions base/special/cos/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,21 @@ var getHighWord = require( '@stdlib/number/float64/base/get-high-word' );
var kernelCos = require( './../../../../base/special/kernel-cos' );
var kernelSin = require( './../../../../base/special/kernel-sin' );
var rempio2 = require( './../../../../base/special/rempio2' );
var ABS_MASK = require( '@stdlib/constants/float64/high-word-abs-mask' );
var EXPONENT_MASK = require( '@stdlib/constants/float64/high-word-exponent-mask' );


// VARIABLES //

// Scratch array for storing temporary values:
var buffer = [ 0.0, 0.0 ]; // WARNING: not thread safe

// High word absolute value mask: 0x7fffffff => 01111111111111111111111111111111
var HIGH_WORD_ABS_MASK = 0x7fffffff|0; // asm type annotation

// High word of π/4: 0x3fe921fb => 00111111111010010010000111111011
var HIGH_WORD_PIO4 = 0x3fe921fb|0; // asm type annotation

// High word of 2^-27: 0x3e400000 => 00111110010000000000000000000000
var HIGH_WORD_TWO_NEG_27 = 0x3e400000|0; // asm type annotation

// High word exponent mask: 0x7ff00000 => 01111111111100000000000000000000
var HIGH_WORD_EXPONENT_MASK = 0x7ff00000|0; // asm type annotation


// MAIN //

Expand Down Expand Up @@ -102,7 +98,7 @@ function cos( x ) {
var n;

ix = getHighWord( x );
ix &= HIGH_WORD_ABS_MASK;
ix &= ABS_MASK;

// Case: |x| ~< pi/4
if ( ix <= HIGH_WORD_PIO4 ) {
Expand All @@ -113,7 +109,7 @@ function cos( x ) {
return kernelCos( x, 0.0 );
}
// Case: cos(Inf or NaN) is NaN */
if ( ix >= HIGH_WORD_EXPONENT_MASK ) {
if ( ix >= EXPONENT_MASK ) {
return NaN;
}
// Case: Argument reduction needed...
Expand Down
6 changes: 6 additions & 0 deletions base/special/cos/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/number/float64/base/get-high-word",
"@stdlib/constants/float64/high-word-abs-mask",
"@stdlib/constants/float64/high-word-exponent-mask",
"@stdlib/math/base/special/kernel-cos",
"@stdlib/math/base/special/kernel-sin",
"@stdlib/math/base/special/rempio2"
Expand All @@ -55,6 +57,8 @@
"libpath": [],
"dependencies": [
"@stdlib/number/float64/base/get-high-word",
"@stdlib/constants/float64/high-word-abs-mask",
"@stdlib/constants/float64/high-word-exponent-mask",
"@stdlib/math/base/special/kernel-cos",
"@stdlib/math/base/special/kernel-sin",
"@stdlib/math/base/special/rempio2"
Expand All @@ -72,6 +76,8 @@
"libpath": [],
"dependencies": [
"@stdlib/number/float64/base/get-high-word",
"@stdlib/constants/float64/high-word-abs-mask",
"@stdlib/constants/float64/high-word-exponent-mask",
"@stdlib/math/base/special/kernel-cos",
"@stdlib/math/base/special/kernel-sin",
"@stdlib/math/base/special/rempio2"
Expand Down
12 changes: 4 additions & 8 deletions base/special/cos/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,19 @@

#include "stdlib/math/base/special/cos.h"
#include "stdlib/number/float64/base/get_high_word.h"
#include "stdlib/constants/float64/high_word_abs_mask.h"
#include "stdlib/constants/float64/high_word_exponent_mask.h"
#include "stdlib/math/base/special/kernel_cos.h"
#include "stdlib/math/base/special/kernel_sin.h"
#include "stdlib/math/base/special/rempio2.h"
#include <stdint.h>

// High word absolute value mask: 0x7fffffff => 01111111111111111111111111111111
static const int32_t HIGH_WORD_ABS_MASK = 0x7fffffff;

// High word of π/4: 0x3fe921fb => 00111111111010010010000111111011
static const int32_t HIGH_WORD_PIO4 = 0x3fe921fb;

// High word of 2^-27: 0x3e400000 => 00111110010000000000000000000000
static const int32_t HIGH_WORD_TWO_NEG_27 = 0x3e400000;

// High word exponent mask: 0x7ff00000 => 01111111111100000000000000000000
static const int32_t HIGH_WORD_EXPONENT_MASK = 0x7ff00000;

/**
* Computes the cosine of a number.
*
Expand Down Expand Up @@ -82,7 +78,7 @@ double stdlib_base_cos( const double x ) {

stdlib_base_float64_get_high_word( x, &uix );
ix = (int32_t)uix;
ix &= HIGH_WORD_ABS_MASK;
ix &= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_ABS_MASK;

// Case: |x| ~< π/4
if ( ix <= HIGH_WORD_PIO4 ) {
Expand All @@ -93,7 +89,7 @@ double stdlib_base_cos( const double x ) {
return stdlib_base_kernel_cos( x, 0.0 );
}
// Case: cos(Inf or NaN) is NaN */
if ( ix >= HIGH_WORD_EXPONENT_MASK ) {
if ( ix >= STDLIB_CONSTANT_FLOAT64_HIGH_WORD_EXPONENT_MASK ) {
return 0.0 / 0.0; // NaN
}
// Case: Argument reduction needed...
Expand Down

0 comments on commit 3704ecf

Please sign in to comment.