tan_simd

Function tan_simd 

Source
pub fn tan_simd<F>(x: &ArrayView1<'_, F>) -> Array1<F>
where F: Float + SimdUnifiedOps,
Expand description

Compute the tangent of each element (SIMD-accelerated).

Computes tan(x) for each element in the array.

§Arguments

  • x - Input 1D array (angles in radians)

§Returns

Array1<F> with the same length as input, with tangent values.

§Performance

  • Auto-vectorization: Compiler optimizations provide excellent performance
  • Speedup: 2-4x on large arrays via auto-vectorization

§Mathematical Definition

tan(x) = sin(x) / cos(x)
Periodic with period π: tan(x + π) = tan(x)
Range: (-∞, ∞)

§Examples

use scirs2_core::ndarray::array;
use scirs2_core::ndarray_ext::elementwise::tan_simd;
use std::f64::consts::PI;

let x = array![0.0_f64, PI/4.0, PI/6.0];
let result = tan_simd(&x.view());

// tan(0) = 0, tan(π/4) = 1

§Edge Cases

  • Empty array: Returns empty array
  • Zero: tan(0) = 0
  • π/2, 3π/2, …: Returns ±infinity (undefined at cos(x)=0)
  • NaN: Returns NaN (preserves NaN)
  • Infinity: Returns NaN (undefined for infinity)

§Applications

  • Computer Graphics: Perspective projection, field of view
  • Navigation: Bearing calculations, angle determination
  • Physics: Slope calculations, inclined planes
  • Image Processing: Gradient direction, edge angles
  • Surveying: Distance and height measurements

§Note on Singularities

Tangent has singularities at x = π/2 + nπ where n is any integer. At these points, cos(x) = 0 and tan(x) approaches ±infinity.