123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239(*
Copyright 2011 Jean-Marc Alliot / Jean-Baptiste Gotteland
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/>.
*)(* Utilities for exponentiation *)externalis_neg:float->bool="is_neg_caml"letinf_powy=ify<0.then0.elseify=0.then1.elseinfinityletzero_powxy=if0.<ythen0.elseify=0.||y=neg_infinity||(is_negx&&floory<>y)thennanelseifis_negx&&mod_floaty2.<>0.thenneg_infinityelseinfinityletneg_inf_powy=ifclassify_floaty=FP_infinite||floory<>ythennanelseify=0.then1.elseify<0.then0.elseifmod_floaty2.=0.theninfinityelseneg_infinityletpos_pow_infx=ifx<1.then0.elseifx=1.then1.elseinfinityletpos_pow_neg_infx=ifx<1.theninfinityelseifx=1.then1.else0.externalflog_pow:float->float->float="flog_pow_caml""flog_pow"[@@unboxed]externalflog_pow_low:float->float->float="flog_pow_low_caml""flog_pow_low"[@@unboxed]externalflog_pow_high:float->float->float="flog_pow_high_caml""flog_pow_high"[@@unboxed](* Operations rounded down. *)moduleLow=structincludeInterval.Lowexternalpow:float->float->float="flog_pow_low_caml""flog_pow_low"[@@unboxed]externalsqrt:float->float="fsqrt_low_caml""fsqrt_low"[@@unboxed]externallog:float->float="flog_low_caml""flog_low"[@@unboxed]externalexp:float->float="fexp_low_caml""fexp_low"[@@unboxed]externalsin:float->float="fsin_low_caml""fsin_low"[@@unboxed]externalcos:float->float="fcos_low_caml""fcos_low"[@@unboxed]externaltan:float->float="ftan_low_caml""ftan_low"[@@unboxed]externalasin:float->float="fasin_low_caml""fasin_low"[@@unboxed]externalacos:float->float="facos_low_caml""facos_low"[@@unboxed]externalatan2:float->float->float="fatan2_low_caml""fatan2_low"[@@unboxed]externalsinh:float->float="fsinh_low_caml""fsinh_low"[@@unboxed]externalcosh:float->float="fcosh_low_caml""fcosh_low"[@@unboxed]externaltanh:float->float="ftanh_low_caml""ftanh_low"[@@unboxed]letatanx=atan2x1.0let(**)xy=ifx=infinitytheninf_powyelseif0.<xthenify=infinitythenpos_pow_infxelseify=neg_infinitythenpos_pow_neg_infxelseflog_pow_lowxyelseifx=0.thenzero_powxyelseifx=neg_infinitythenneg_inf_powyelseifclassify_floaty=FP_infinite||floory<>ythennanelseifmod_floaty2.=0.thenflog_pow_low(-.x)yelse-.flog_pow_high(-.x)yend(* Operations rounded up. *)moduleHigh=structincludeInterval.Highexternalpow:float->float->float="flog_pow_high_caml""flog_pow_high"[@@unboxed]externalsqrt:float->float="fsqrt_high_caml""fsqrt_high"[@@unboxed]externallog:float->float="flog_high_caml""flog_high"[@@unboxed]externalexp:float->float="fexp_high_caml""fexp_high"[@@unboxed]externalsin:float->float="fsin_high_caml""fsin_high"[@@unboxed]externalcos:float->float="fcos_high_caml""fcos_high"[@@unboxed]externaltan:float->float="ftan_high_caml""ftan_high"[@@unboxed]externalasin:float->float="fasin_high_caml""fasin_high"[@@unboxed]externalacos:float->float="facos_high_caml""facos_high"[@@unboxed]externalatan2:float->float->float="fatan2_high_caml""fatan2_high"[@@unboxed]externalsinh:float->float="fsinh_high_caml""fsinh_high"[@@unboxed]externalcosh:float->float="fcosh_high_caml""fcosh_high"[@@unboxed]externaltanh:float->float="ftanh_high_caml""ftanh_high"[@@unboxed]letatanx=atan2x1.0let(**)xy=ifx=infinitytheninf_powyelseif0.<xthenify=infinitythenpos_pow_infxelseify=neg_infinitythenpos_pow_neg_infxelseflog_pow_highxyelseifx=0.thenzero_powxyelseifx=neg_infinitythenneg_inf_powyelseifclassify_floaty=FP_infinite||floory<>ythennanelseifmod_floaty2.=0.thenflog_pow_high(-.x)yelse-.flog_pow_low(-.x)yendexternalffloat:int->float="ffloat_caml"letffloat_high=High.floatletffloat_low=Low.floatexternalfadd:float->float->float="fadd_caml""fadd"[@@unboxed]letfadd_low=Low.(+.)letfadd_high=High.(+.)externalfsub:float->float->float="fsub_caml""fsub"[@@unboxed]letfsub_low=Low.(-.)letfsub_high=High.(-.)externalfmul:float->float->float="fmul_caml""fmul"[@@unboxed]letfmul_low=Low.(*.)letfmul_high=High.(*.)externalfdiv:float->float->float="fdiv_caml""fdiv"[@@unboxed]letfdiv_low=Low.(/.)letfdiv_high=High.(/.)externalfmod:float->float->float="fprem_caml""fprem"[@@unboxed]externalfsqrt:float->float="fsqrt_caml""fsqrt"[@@unboxed]letfsqrt_low=Low.sqrtletfsqrt_high=High.sqrtexternalflog:float->float="flog_caml""flog"[@@unboxed]letflog_low=Low.logletflog_high=High.logexternalfexp:float->float="fexp_caml""fexp"[@@unboxed]letfexp_low=Low.expletfexp_high=High.expexternalfsin:float->float="fsin_caml""fsin"[@@unboxed]letfsin_low=Low.sinletfsin_high=High.sinexternalfcos:float->float="fcos_caml""fcos"[@@unboxed]letfcos_low=Low.cosletfcos_high=High.cosexternalftan:float->float="ftan_caml""ftan"[@@unboxed]letftan_low=Low.tanletftan_high=High.tanexternalfasin:float->float="fasin_caml""fasin"[@@unboxed]letfasin_low=Low.asinletfasin_high=High.asinexternalfacos:float->float="facos_caml""facos"[@@unboxed]letfacos_low=Low.acosletfacos_high=High.acosexternalfatan:float->float->float="fatan_caml""fatan"[@@unboxed]letfatan_lowxy=Low.atan2yxletfatan_highxy=High.atan2yxexternalfsinh:float->float="fsinh_caml""fsinh"[@@unboxed]letfsinh_low=Low.sinhletfsinh_high=High.sinhexternalfcosh:float->float="fcosh_caml""fcosh"[@@unboxed]letfcosh_low=Low.coshletfcosh_high=High.coshexternalftanh:float->float="ftanh_caml""ftanh"[@@unboxed]letftanh_low=Low.tanhletftanh_high=High.tanhletfpowxy=ifx=infinitytheninf_powyelseif0.<xthenify=infinitythenpos_pow_infxelseify=neg_infinitythenpos_pow_neg_infxelseflog_powxyelseifx=0.thenzero_powxyelseifx=neg_infinitythenneg_inf_powyelseifclassify_floaty=FP_infinite||floory<>ythennanelseifmod_floaty2.=0.thenflog_pow(-.x)yelse-.flog_pow(-.x)yletfpow_low=Low.(**)letfpow_high=High.(**)moduleRename=structletmod_float=fmodletsqrt=fsqrtletlog=flogletexp=fexplet(**)=fpowletcos=fcosletsin=fsinlettan=ftanletasin=fasinletacos=facosletatanx=fatan1.0xletatan2yx=fatanxyletcosh=fcoshletsinh=fsinhlettanh=ftanhendmoduleRename_all=structlet(+.)=faddlet(-.)=fsublet(*.)=fmullet(/.)=fdivletmod_float=fmodletsqrt=fsqrtletlog=flogletexp=fexplet(**)=fpowletcos=fcosletsin=fsinlettan=ftanletasin=fasinletacos=facosletatanx=fatan1.0xletatan2yx=fatanxyletcosh=fcoshletsinh=fsinhlettanh=ftanhend