ComfyUI Node

tan

The trig node that knows when it's undefined

By StableLlama·Created about a year ago·Updated 4 days ago· 48
tan
  • angle
  • FLOAT
unitdegrees

Tangent is sine divided by cosine - and because cosine hits zero at 90°, 270°, and every 180° after that, tangent is undefined at those angles. Most math nodes would just let that blow up into a cryptic division-by-zero. The tan node from Basic data handling actually catches it and tells you, in plain words, "Tangent is undefined at this angle (division by zero)." It's a small thing, but it's the difference between a readable error and an hour of debugging.

For what it's worth, that's the kind of attention to edge cases that makes this pack pleasant to use - it was clearly written by someone who hit these errors themselves.

How it works

Like sin, the node wraps Python's math.tan() and adds a unit dropdown:

  • angle - FLOAT or INT, default 0.
  • unit - radians or degrees (default degrees). Pick degrees and it converts internally before computing.

Output is a single FLOAT. Unlike sine and cosine, tangent has no fixed range - it runs from -∞ to +∞ and passes through 0 at every multiple of 180°.

The one real gotcha: the vertical asymptotes

tan(90°) and tan(270°) (and -90°, 450°, ...) don't exist. The node raises a ValueError for exactly those angles - it checks whether cosine is effectively zero and refuses rather than returning a nonsense float. Two practical consequences:

  1. Don't feed a schedule that lands on 90°. If your angle counter can hit 90 or 270 exactly, the node will throw. Nudge the range, or clamp it slightly off the asymptote.
  2. Tiny angles near the asymptote are fine but huge. tan(89.9°) is around 573. That's mathematically correct, but it means a small wobble in your input produces enormous output swings. If you're using tangent for a smooth wave, sin or cos is usually the saner choice - tangent is better for ratios and slopes than for oscillation.

Where you'd reach for it

Tangent is the ratio of opposite to adjacent - so it's the natural fit for computing slopes, angles from aspect ratios (atan is the inverse for that), or any geometry where you have two sides and want the angle or the pitch.

Installing it

Basic data handling is a zero-dependency pack: no models, no pip installs. ComfyUI Manager → search "Basic data handling" → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart, and tan is under Basic/maths next to sin and cos.

The take

You'll use sin and cos more, full stop. But when tangent is the right tool, this is the version that fails helpfully instead of cryptically - and that alone justifies the node existing.

CategoryBasic/maths

Inputs (2)

NameTypeDefaultDescription
angleFLOAT,INT0
unitCOMBOdegrees2 options: radians, degrees

Outputs (1)

NameTypeDescription
FLOATFLOAT