RunMat
GitHub

atan — Element-wise inverse tangent matching MATLAB semantics for real, logical, character, and complex inputs with GPU fallbacks.

Y = atan(X) computes the inverse tangent (in radians) of every element of X. The operation runs element-wise, supports real and complex numbers, and honors MATLAB's broadcasting semantics.

How atan works in RunMat

  • Works on scalars, vectors, matrices, and N-D tensors, including logical and integer inputs (which are promoted to double precision before evaluation).
  • Character arrays are interpreted as their Unicode code points and return dense double arrays of identical shape.
  • Complex inputs follow MATLAB's analytic extension atan(z) = (1/(2i)) * (log(1 + i z) - log(1 - i z)), ensuring identical branch behavior and NaN/Inf propagation.
  • Returns results in radians for real inputs and complex numbers for complex inputs.
  • Empty arrays and already scalar values pass straight through while preserving shape.

How atan runs on the GPU

When RunMat Accelerate is active and the selected provider implements unary_atan, the runtime keeps tensors on the GPU and executes the kernel entirely on-device.

If the provider lacks unary_atan (or declines the request), RunMat gathers the data to the host, computes the result with the reference implementation, and then reapplies residency requests such as 'like' prototypes automatically.

Fusion planning groups neighboring elementwise operations so downstream kernels can stay on the GPU even if atan itself fell back to the CPU.

GPU memory and residency

Usually you do **not** need to call gpuArray. When a provider exposes unary_atan, the runtime keeps data on the GPU automatically. If the hook is missing (or if you supply a host 'like' prototype), RunMat gathers and computes on the CPU, then honors the requested residency so you do not have to manage transfers manually.

Examples

Arctangent of a scalar

y = atan(1)

Expected output:

y = 0.7854

Element-wise arctangent of a vector

x = linspace(-2, 2, 5);
angles = atan(x)

Expected output:

angles = [-1.1071  -0.7854         0    0.7854    1.1071]

Computing inverse tangent of every entry in a matrix

A = [-2 -1 0; 1 2 3];
Y = atan(A)

Expected output:

Y =
   -1.1071   -0.7854         0
    0.7854    1.1071    1.2490

Evaluating atan on a complex number

z = 1 + 2i;
w = atan(z)

Expected output:

w = 1.3390 + 0.4024i

Keeping the result on the GPU with 'like'

proto = gpuArray.zeros(1, 1);
G = gpuArray([-3 -1 0 1 3]);
deviceResult = atan(G, 'like', proto);
result = gather(deviceResult)

Expected output:

result =
   -1.2490   -0.7854         0    0.7854    1.2490

Inspecting character codes via inverse tangent

codes = atan('RUN')

Expected output:

codes =
    1.5586    1.5590    1.5580

FAQ

When should I use atan?

Use atan whenever you need the element-wise inverse tangent of data expressed in radians—common in signal processing, control systems, and geometric computations.

How is atan different from atan2?

atan accepts a single input and returns results in (-π/2, π/2). atan2(y, x) takes two inputs, uses the signs of both arguments to determine the correct quadrant, and returns values in (-π, π].

Does atan support complex numbers?

Yes. Results match MATLAB's analytic continuation of the inverse tangent and may return complex values even for real inputs when the computation requires it.

Can I keep results on the GPU?

Yes. Passing 'like', prototype with a GPU tensor keeps outputs on-device whenever a provider is registered. When the provider lacks unary_atan, RunMat computes on the host and returns host data unless you explicitly request GPU residency via 'like'.

What happens with NaN or Inf inputs?

NaNs propagate, and infinities map to the appropriate asymptotic limits (atan(±Inf) = ±π/2), matching MATLAB's IEEE behavior.

These functions work well alongside atan. Each page has runnable examples you can try in the browser.

atan2, tan, asin, acos, gpuArray, gather, acosh, asinh, atanh, cos, cosh, sin, sinh, tanh

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how atan works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat — free, no sign-up

Start running MATLAB code immediately in your browser.