Skip to content

scaledRootMeanSquare

scaledRootMeanSquare(x): number

Defined in: src/scaled_root_mean_square.js:22

The root mean square computed by scaling, which is an equivalent way of computing rootMeanSquare suitable for values whose squares leave floating point range.

rootMeanSquare sums the squares directly, so it returns Infinity once a value exceeds about 1e154 and 0 once every value falls below about 1e-162. This function divides through by the largest magnitude first, so the squares it sums are all at most one.

It runs in O(n), linear time, with respect to the length of the array, in two passes rather than one.

number[]

a sample of one or more data points

number

root mean square

if x is empty

scaledRootMeanSquare([-1, 1, -1, 1]); // => 1
scaledRootMeanSquare([1e200, 2e200, 3e200]); // => 2.1602468994692866e+200