// Generated by bynkc — do not edit by hand.
// commons nums

import { Ok, Err, Some, None, type Result, type Option, type ValidationError } from "./runtime.js";

export function distance(a: number, b: number): number {
  return Math.abs((a - b));
}

export function bounded(x: number, lo: number, hi: number): number {
  return Math.min(Math.max(x, lo), hi);
}

export function extremes(a: number, b: number): number {
  return Math.min(a, b) + Math.max(a, b);
}

export function safeRatio(a: number, b: number): Option<number> {
  const r = a / b;
  return (Number.isFinite(r) ? Some(r) : None);
}

export function neverNaN(x: number): boolean {
  return Number.isNaN(x) === false;
}

export function parseOrZero(s: string): number {
  return ((__o: Option<number>, __d: number) => __o.tag === "Some" ? __o.value : __d)(((__s: string) => { const __n = __s.trim() === "" ? Number.NaN : Number(__s); return Number.isSafeInteger(__n) ? Some(__n) : None; })(s), 0);
}

export function parsePrice(s: string): Option<number> {
  return ((__s: string) => { const __n = __s.trim() === "" ? Number.NaN : Number(__s); return Number.isFinite(__n) ? Some(__n) : None; })(s);
}

