From 55e92b4629b340fb59542ac9295fc64e227d3ddd Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 28 Mar 2018 19:53:02 -0500 Subject: [PATCH] feat(mono): add dotted comparison operators for floats closes #196 --- src/core/CCString.ml | 4 ++-- src/monomorphic/CCMonomorphic.ml | 8 ++++++++ src/monomorphic/CCMonomorphic.mli | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/core/CCString.ml b/src/core/CCString.ml index 518ffd06..704eedd8 100644 --- a/src/core/CCString.ml +++ b/src/core/CCString.ml @@ -696,7 +696,7 @@ let prefix ~pre s = else ( let rec check i = if i=len then true - else if String.unsafe_get s i != String.unsafe_get pre i then false + else if not (Char.equal (String.unsafe_get s i) (String.unsafe_get pre i)) then false else check (i+1) in check 0 @@ -719,7 +719,7 @@ let suffix ~suf s = let off = String.length s - len in let rec check i = if i=len then true - else if String.unsafe_get s (off+i) != String.unsafe_get suf i then false + else if not (Char.equal (String.unsafe_get s (off+i)) (String.unsafe_get suf i)) then false else check (i+1) in check 0 diff --git a/src/monomorphic/CCMonomorphic.ml b/src/monomorphic/CCMonomorphic.ml index 3817b80a..28e2ed2f 100644 --- a/src/monomorphic/CCMonomorphic.ml +++ b/src/monomorphic/CCMonomorphic.ml @@ -3,4 +3,12 @@ include Pervasives +let (=.) : float -> float -> bool = (=) +let (<>.) : float -> float -> bool = (<>) +let (<.) : float -> float -> bool = (<) +let (>.) : float -> float -> bool = (>) +let (<=.) : float -> float -> bool = (<=) +let (>=.) : float -> float -> bool = (>=) + let (==) = `Consider_using_CCEqual_physical +let (!=) = `Consider_using_CCEqual_physical diff --git a/src/monomorphic/CCMonomorphic.mli b/src/monomorphic/CCMonomorphic.mli index 382fd003..a188c82b 100644 --- a/src/monomorphic/CCMonomorphic.mli +++ b/src/monomorphic/CCMonomorphic.mli @@ -15,5 +15,25 @@ val compare : int -> int -> int val min : int -> int -> int val max : int -> int -> int +(** {2 Infix operators for Floats} *) + +val (=.) : float -> float -> bool (** @since NEXT_RELEASE *) + +val (<>.) : float -> float -> bool (** @since NEXT_RELEASE *) + +val (<.) : float -> float -> bool (** @since NEXT_RELEASE *) + +val (>.) : float -> float -> bool (** @since NEXT_RELEASE *) + +val (<=.) : float -> float -> bool (** @since NEXT_RELEASE *) + +val (>=.) : float -> float -> bool (** @since NEXT_RELEASE *) + +(** {2 Shadow Dangerous Operators} *) + val (==) : [`Consider_using_CCEqual_physical] [@@ocaml.deprecated "Please use CCEqual.physical or Pervasives.(==) instead."] + +(** @since NEXT_RELEASE *) +val (!=) : [`Consider_using_CCEqual_physical] +[@@ocaml.deprecated "Please use [not CCEqual.physical] or Pervasives.(!=) instead."]