rempio2
Compute
x - nπ/2 = r
.
Usage
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
rempio2( x, y )
Computes x - nπ/2 = r
.
var y = [ 0.0, 0.0 ];
var n = rempio2( 128.0, y );
// returns 81
var y1 = y[ 0 ];
// returns ~0.765
var y2 = y[ 1 ];
// returns ~3.618e-17
When x
is NaN
or infinite, the function returns 0
and sets the elements of y
to NaN
.
var y = [ 0.0, 0.0 ];
var n = rempio2( NaN, y );
// returns 0
var y1 = y[ 0 ];
// returns NaN
var y2 = y[ 1 ];
// returns NaN
y = [ 0.0, 0.0 ];
n = rempio2( Infinity, y );
// returns 0
y1 = y[ 0 ];
// returns NaN
y2 = y[ 1 ];
// returns NaN
Notes
- The function returns
n
and stores the remainderr
as two numbers iny
, such thaty[0]+y[1] = r
. - For input values larger than
2^20*π/2
in magnitude, the function only returns the last three binary digits ofn
and not the full result.
Examples
var linspace = require( '@stdlib/array/base/linspace' );
var rempio2 = require( '@stdlib/math/base/special/rempio2' );
var x = linspace( 0.0, 100.0, 100 );
var y = [ 0.0, 0.0 ];
var n;
var i;
for ( i = 0; i < x.length; i++ ) {
n = rempio2( x[ i ], y );
console.log( '%d - %dπ/2 = %d + %d', x[ i ], n, y[ 0 ], y[ 1 ] );
}
C APIs
Usage
#include "stdlib/math/base/special/rempio2.h"
stdlib_base_rempio2( x, &rem1, &rem2 )
Computes x - nπ/2 = r
.
#include <stdint.h>
double rem1;
double rem2;
int32_t n = stdlib_base_rempio2( 4.0, &rem1, &rem2 );
The function accepts the following arguments:
- x:
[in] double
input value. - rem1:
[out] double*
destination for first remainder number. - rem2:
[out] double*
destination for second remainder number.
int32_t stdlib_base_rempio2( const double x, double *rem1, double *rem2 );
Notes
- The function returns
n
and stores the remainderr
as two numbers inrem1
andrem2
, respectively, such thatrem1+rem2 = r
.
Examples
#include "stdlib/math/base/special/rempio2.h"
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main( void ) {
const double x[] = { 0.0, 1.0, 4.0, 128.0 };
double rem1;
double rem2;
int32_t n;
int i;
for ( i = 0; i < 4; i++ ) {
n = stdlib_base_rempio2( x[ i ], &rem1, &rem2 );
printf( "%lf - %"PRId32"π/2 = %lf + %lf\n", x[ i ], n, rem1, rem2 );
}
}