Skip to content

Modern Math CNorm

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › Math Library › Math Library › CNorm

CNorm

Returns the modulus squared, the cheap way to compare sizes.

Syntax

CNorm( byref z as Complex ) as float64

Notes

  • The one to use for comparisons. CNorm(a) < CNorm(b) answers the same question as CAbs(a) < CAbs(b) without either square root.
  • z * CConj( z ) is CNorm( z ) with a zero imaginary part — that identity is what the name means.
  • It does overflow where CAbs does not: it is the squared quantity, and squaring 1e200 is inf.
  • AfxNova spelled this CNorm, CAbs2 and CAbsSqr.

Examples

#import "std/numeric"
using numeric

print CNorm( CSet( 3, 4 ) )                              '' 25
print CToString( CSet( 3, 4 ) * CConj( CSet( 3, 4 ) ) )  '' 25+0i   -- real, and equal to CNorm
print CNorm( CSet( 1e200, 1e200 ) )                      '' 1.#INF   -- this one DOES overflow -- use CAbs

Library: Math Library
Category: Math Library
Documented under: Members

Clone this wiki locally