Routine Name: Hardware Epsilon
Author: Kyle Hovey
Language: C++
Description/Purpose:
This templated function is designed to compute the hardware epsilon on any machine using an abstract type defined per-use-case.
From Wikipedia:
Machine epsilon gives an upper bound on the relative error due to rounding in floating point arithmetic. This value characterizes computer arithmetic in the field of numerical analysis, and by extension in the subject of computational science. The quantity is also called macheps or unit roundoff, and it has the symbols Greek epsilon \( \epsilon \) or bold Roman \( u \), respectively.
Input:
Either nothing, or a starting value to compute epsilon from.
Output:
The machine epsilon for the computer that the code runs on.
Usage/Example:
To use this function, you have to include it in the file you need to call it from.
Output:
Implementation/Code:
To find the smallest quanta represented in a floating type T
, I wrote a templated function that will reduce the exponent (by dividing by two) of an epsilon
value of type T
until it becomes an identity element under floating point addition. To ensure that it is the identity, I will add it to an integer and ensure that it is unchanged after the operation: