Skip to content

Instantly share code, notes, and snippets.

View stephentyrone's full-sized avatar

Stephen Canon stephentyrone

View GitHub Profile
@stephentyrone
stephentyrone / minmax.md
Last active September 15, 2017 16:18
Notes on how min/max might be defined.

Defining min and max

Most definitions of floating-point min and max are badly flawed; this note explains what axioms these functions should have, illustrates the problems with existing definitions, and explores the options for fixing the situation.

Note: min and max should be symmetric, so it suffices to restrict our attention to one of them. For most of the rest of this document, I'll explain everything using min. The appropriate modifications to get max should generally be pretty clear.

Desired axioms

The first two axioms capture the meaning of minimum; they will likely seem completely obvious (possible the point of absurdity).

#import <Foundation/Foundation.h>
#import <mach/mach_time.h>
#import <simd/simd.h>
NSTimeInterval SecondsFromMachTimeInterval(uint64_t machTimeInterval) {
static double timeScaleSeconds = 0.0;
if (timeScaleSeconds == 0.0) {