File: gsl_math.ml

package info (click to toggle)
ocamlgsl 0.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 4,024 kB
  • ctags: 3,091
  • sloc: ml: 8,539; ansic: 7,338; makefile: 262; sh: 150; awk: 13
file content (71 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(* ocamlgsl - OCaml interface to GSL                        *)
(* Copyright (©) 2002-2005 - Olivier Andrieu                *)
(* distributed under the terms of the GPL version 2         *)

let e          = 2.71828182845904523536028747135 (* e *)

let log2e      = 1.44269504088896340735992468100 (* log_2 (e) *)

let log10e     = 0.43429448190325182765112891892 (* log_10 (e) *)

let sqrt2      = 1.41421356237309504880168872421 (* sqrt(2) *)

let sqrt1_2    = 0.70710678118654752440084436210 (* sqrt(1/2) *)

let sqrt3      = 1.73205080756887729352744634151 (* sqrt(3) *)

let pi         = 3.14159265358979323846264338328 (* pi *)

let pi_2       = 1.57079632679489661923132169164 (* pi/2 *)

let pi_4       = 0.78539816339744830966156608458 (* pi/4 *)

let sqrtpi     = 1.77245385090551602729816748334 (* sqrt(pi) *)

let i_2_sqrtpi = 1.12837916709551257389615890312 (* 2/sqrt(pi) *)

let i_1_pi     = 0.31830988618379067153776752675 (* 1/pi *)

let i_2_pi     = 0.63661977236758134307553505349 (* 2/pi *)

let ln10       = 2.30258509299404568401799145468 (* ln(10) *)

let ln2        = 0.69314718055994530941723212146 (* ln(2) *)

let lnpi       = 1.14472988584940017414342735135 (* ln(pi) *)

let euler      = 0.57721566490153286060651209008 (* Euler constant *)


let rec unsafe_pow_int x = function
  | 1 -> x
  | n when n mod 2 = 0 ->
      unsafe_pow_int (x *. x) (n/2)
  | n ->
      x *. (unsafe_pow_int x (pred n))

let pow_int x = function
  | 0 -> 1.
  | n when n > 0 -> unsafe_pow_int x n 
  | _ -> invalid_arg "pow_int"

external log1p : float -> float
    = "ml_gsl_log1p" "gsl_log1p" "float"

external expm1 : float -> float
    = "ml_gsl_expm1" "gsl_expm1" "float"

external hypot : float -> float -> float
    = "ml_gsl_hypot" "gsl_hypot" "float"

external acosh : float -> float
    = "ml_gsl_acosh" "gsl_acosh" "float"

external asinh : float -> float
    = "ml_gsl_asinh" "gsl_asinh" "float"

external atanh : float -> float
    = "ml_gsl_atanh" "gsl_atanh" "float"

external fcmp : float -> float -> epsilon:float -> int
    = "ml_gsl_fcmp"