liveBook · Manning

Unchecked-negate

As explained in Clojure: The Essential Reference

unchecked-negate is a Clojure function that negates a numeric value without checking for numeric overflow.

unchecked-negate negates one numeric value without checking for integer overflow. It belongs to Clojure’s unchecked-* operators and returns the corresponding numeric result. section 5.13

Its contract is narrow:

  • Accepts exactly one numeric argument. section 5.13
  • Returns the negated value, with the result type determined by numeric type contagion. section 5.13
  • Omits integer-overflow checking, making unchecked arithmetic useful for operations such as hashing. section 5.13

Basic negation

(unchecked-negate 1) ;; -1

How Clojure: The Essential Reference covers it

How deep it goes
Defines arity, numeric output, type contagion, and unchecked overflow behavior, without detailing implementation internals.
Examples
Demonstrates (unchecked-negate 1) returning -1.
What it assumes
Assumes familiarity with Clojure numeric values and introduces the restricted arity of unchecked arithmetic.
What you can do after
Apply it via Clojure as a one-argument unchecked numeric negation operation.
How it connects
Connects unchecked-negate to unchecked operators, numeric types, type promotion, integer overflow, and hashing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.