1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374(*
Copyright 2011 Jean-Marc Alliot / Jean-Baptiste Gotteland
Copyright 2018 Christophe Troestler
This file is part of the ocaml interval library.
The ocaml interval library is free software:
you can redistribute it and/or modify it under the terms of
the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The ocaml interval library is distributed in the hope that it will be
useful,but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the ocaml interval library.
If not, see <http://www.gnu.org/licenses/>.
*)(** Implementation of interval functions that can be shared with the
Interval_crlibm library. (Trigonometric functions depend on
argument reduction which is performed differently.) *)openIntervalmoduleLow=Fpu.LowmoduleHigh=Fpu.Highlet[@inline]mod2x=Fpu.fmodx2.(* [min] and [max], specialized to floats (faster).
NaN do dot need to be handled. *)letfmin(a:float)(b:float)=ifa<=bthenaelsebletfmax(a:float)(b:float)=ifa<=bthenbelsealetlog{low=a;high=b}=ifb<=0.thenraise(Domain_error"log")else{low=ifa<=0.thenneg_infinityelseLow.loga;high=High.logb}letexp{low=a;high=b}={low=ifa=neg_infinitythen0.elseLow.expa;high=ifb=infinitytheninfinityelseHigh.expb}letmax_63=ldexp1.63lettan{low=a;high=b}=if-.max_63<=a&&b<=max_63&&Interval.High.(b-.a<pi)then(letta=Low.tanainlettb=High.tanbinifta<=tbthen{low=ta;high=tb}elseInterval.I.entire)elseInterval.I.entireletacos{low=a;high=b}=ifa<=1.&&-1.<=bthen{low=ifb<1.thenLow.acosbelse0.;high=if-1.<athenHigh.acosaelseInterval.High.pi}elseraise(Domain_error"acos")letasin{low=a;high=b}=ifa<=1.&&-1.<=bthen{low=if-1.<athenLow.asinaelse-.Interval.High.half_pi;high=ifb<1.thenHigh.asinbelseInterval.High.half_pi}elseraise(Domain_error"asin")letcosh{low=a;high=b}=ifb<0.then{low=Low.coshb;high=High.cosha}elseifa<0.then{low=1.;high=High.cosh(fmax(-.a)b)}else{low=Low.cosha;high=High.coshb}letsinh{low=a;high=b}={low=Low.sinha;high=High.sinhb}