Skip to content

Instantly share code, notes, and snippets.

Stephen Canon stephentyrone

Block or report user

Report or block stephentyrone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stephentyrone
stephentyrone / minmax.md
Last active Sep 15, 2017
Notes on how min/max might be defined.
View minmax.md

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).

View gist:228144648ee250a4ba07
#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) {
You can’t perform that action at this time.