Skip to content

PromQL: Trigonometric functions should return NaN for out-of-range inputs instead of throwing exceptions #142495

@sidosera

Description

@sidosera

Description

PromQL trigonometric functions (e.g. atanh, acos, asin) currently throw an ArithmeticException when given out-of-range inputs. For example, atanh(2) throws rather than returning NaN.

In PromQL, these functions are expected to return NaN for out-of-range inputs instead of raising errors. This difference affects compatibility with Prometheus behavior.

Current behavior

atanh(2) → ArithmeticException: Atanh input out of range

Expected PromQL behavior

atanh(2) → NaN

Affected functions

  • atanh (input outside [-1, 1])
  • acos (input outside [-1, 1])
  • asin (input outside [-1, 1])
  • Potentially other trigonometric functions with domain restrictions

Proposal

Either create PromQL-specific variants of these functions that return NaN, or add a wrapping mechanism that catches ArithmeticException and returns NaN when invoked from a PromQL context.

Context

Discussed in #142213 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions