PR#3806, 4752, 5246: added "hypot" and "copysign" to Pervasives.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11065 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
e6d76ed5b1
commit
174ff0b018
9
Changes
9
Changes
|
@ -4,6 +4,15 @@ OCaml 3.13.0:
|
|||
- The official name of the language is now OCaml.
|
||||
- Warning 28 is now enabled by default.
|
||||
|
||||
Standard library:
|
||||
- Added float functions "hypot" and "copysign" (PR#3806, PR#4752, PR#5246)
|
||||
- Hashtbl:
|
||||
. Statistically-better generic hash function based on Murmur 3 (PR#5225)
|
||||
. Fixed behavior of generic hash function w.r.t. -0.0 and NaN (PR#5222)
|
||||
. Added optional "seed" parameter to Hashtbl.create for diversification
|
||||
. Added new functorial interface "MakeSeeded" to support diversification
|
||||
with user-provided hash functions.
|
||||
|
||||
|
||||
Objective Caml 3.12.0:
|
||||
----------------------
|
||||
|
|
BIN
boot/ocamlc
BIN
boot/ocamlc
Binary file not shown.
BIN
boot/ocamldep
BIN
boot/ocamldep
Binary file not shown.
BIN
boot/ocamllex
BIN
boot/ocamllex
Binary file not shown.
|
@ -326,12 +326,32 @@ CAMLprim value caml_ceil_float(value f)
|
|||
return caml_copy_double(ceil(Double_val(f)));
|
||||
}
|
||||
|
||||
CAMLexport double caml_hypot(double x, double y)
|
||||
{
|
||||
#ifdef HAS_C99_FLOAT_OPS
|
||||
return hypot(x, y);
|
||||
#else
|
||||
double tmp, ratio;
|
||||
if (x != x) return x; /* NaN */
|
||||
if (y != y) return y; /* NaN */
|
||||
x = fabs(x); y = fabs(y);
|
||||
if (x < y) { tmp = x; x = y; y = tmp; }
|
||||
if (x == 0.0) return 0.0;
|
||||
ratio = y / x;
|
||||
return x * sqrt(1.0 + ratio * ratio);
|
||||
#endif
|
||||
}
|
||||
|
||||
CAMLprim value caml_hypot_float(value f, value g)
|
||||
{
|
||||
return caml_copy_double(caml_hypot(Double_val(f), Double_val(g)));
|
||||
}
|
||||
|
||||
/* These emulations of expm1() and log1p() are due to William Kahan.
|
||||
See http://www.plunk.org/~hatch/rightway.php */
|
||||
|
||||
CAMLexport double caml_expm1(double x)
|
||||
{
|
||||
#ifdef HAS_EXPM1_LOG1P
|
||||
#ifdef HAS_C99_FLOAT_OPS
|
||||
return expm1(x);
|
||||
#else
|
||||
double u = exp(x);
|
||||
|
@ -345,7 +365,7 @@ CAMLexport double caml_expm1(double x)
|
|||
|
||||
CAMLexport double caml_log1p(double x)
|
||||
{
|
||||
#ifdef HAS_EXPM1_LOG1P
|
||||
#ifdef HAS_C99_FLOAT_OPS
|
||||
return log1p(x);
|
||||
#else
|
||||
double u = 1. + x;
|
||||
|
@ -366,6 +386,34 @@ CAMLprim value caml_log1p_float(value f)
|
|||
return caml_copy_double(caml_log1p(Double_val(f)));
|
||||
}
|
||||
|
||||
union double_as_two_int32 {
|
||||
double d;
|
||||
#if defined(ARCH_BIG_ENDIAN) || (defined(__arm__) && !defined(__ARM_EABI__))
|
||||
struct { uint32 h; uint32 l; } i;
|
||||
#else
|
||||
struct { uint32 l; uint32 h; } i;
|
||||
#endif
|
||||
};
|
||||
|
||||
CAMLexport double caml_copysign(double x, double y)
|
||||
{
|
||||
#ifdef HAS_C99_FLOAT_OPS
|
||||
return copysign(x, y);
|
||||
#else
|
||||
union double_as_two_int32 ux, uy;
|
||||
ux.d = x;
|
||||
uy.d = y;
|
||||
ux.i.h &= 0x7FFFFFFFU;
|
||||
ux.i.h |= (uy.i.h & 0x80000000U);
|
||||
return ux.d;
|
||||
#endif
|
||||
}
|
||||
|
||||
CAMLprim value caml_copysign_float(value f, value g)
|
||||
{
|
||||
return caml_copy_double(caml_copysign(Double_val(f), Double_val(g)));
|
||||
}
|
||||
|
||||
CAMLprim value caml_eq_float(value f, value g)
|
||||
{
|
||||
return Val_bool(Double_val(f) == Double_val(g));
|
||||
|
@ -429,14 +477,7 @@ CAMLprim value caml_classify_float(value vd)
|
|||
return Val_int(FP_normal);
|
||||
}
|
||||
#else
|
||||
union {
|
||||
double d;
|
||||
#if defined(ARCH_BIG_ENDIAN) || (defined(__arm__) && !defined(__ARM_EABI__))
|
||||
struct { uint32 h; uint32 l; } i;
|
||||
#else
|
||||
struct { uint32 l; uint32 h; } i;
|
||||
#endif
|
||||
} u;
|
||||
union double_as_two_int32 u;
|
||||
uint32 h, l;
|
||||
|
||||
u.d = Double_val(vd);
|
||||
|
|
|
@ -52,10 +52,10 @@
|
|||
/* Define SUPPORT_DYNAMIC_LINKING if dynamic loading of C stub code
|
||||
via dlopen() is available. */
|
||||
|
||||
#define HAS_EXPM1_LOG1P
|
||||
#define HAS_C99_FLOAT_OPS
|
||||
|
||||
/* Define HAS_EXPM1_LOG1P if the math functions expm1() and log1p()
|
||||
are available. (Standard C99 but not C89.) */
|
||||
/* Define HAS_C99_FLOAT_OPS if <math.h> conforms to ISO C99.
|
||||
In particular, it should provide expm1(), log1p(), hypot(), copysign(). */
|
||||
|
||||
/* 2. For the Unix library. */
|
||||
|
||||
|
|
|
@ -869,9 +869,9 @@ fi
|
|||
|
||||
# For the Pervasives module
|
||||
|
||||
if sh ./trycompile expm1.c $mathlib; then
|
||||
echo "expm1() and log1p() found."
|
||||
echo "#define HAS_EXPM1_LOG1P" >> s.h
|
||||
if sh ./hasgot2 -i math.h $mathlib expm1 log1p hypot copysign; then
|
||||
echo "expm1(), log1p(), hypot(), copysign() found."
|
||||
echo "#define HAS_C99_FLOAT_OPS" >> s.h
|
||||
fi
|
||||
|
||||
# For the Sys module
|
||||
|
|
|
@ -94,6 +94,7 @@ external acos : float -> float = "caml_acos_float" "acos" "float"
|
|||
external asin : float -> float = "caml_asin_float" "asin" "float"
|
||||
external atan : float -> float = "caml_atan_float" "atan" "float"
|
||||
external atan2 : float -> float -> float = "caml_atan2_float" "atan2" "float"
|
||||
external hypot : float -> float -> float = "caml_hypot_float" "caml_hypot" "float"
|
||||
external cos : float -> float = "caml_cos_float" "cos" "float"
|
||||
external cosh : float -> float = "caml_cosh_float" "cosh" "float"
|
||||
external log : float -> float = "caml_log_float" "log" "float"
|
||||
|
@ -107,6 +108,7 @@ external tanh : float -> float = "caml_tanh_float" "tanh" "float"
|
|||
external ceil : float -> float = "caml_ceil_float" "ceil" "float"
|
||||
external floor : float -> float = "caml_floor_float" "floor" "float"
|
||||
external abs_float : float -> float = "%absfloat"
|
||||
external copysign : float -> float -> float = "caml_copysign_float" "caml_copysign" "float"
|
||||
external mod_float : float -> float -> float = "caml_fmod_float" "fmod" "float"
|
||||
external frexp : float -> float * int = "caml_frexp_float"
|
||||
external ldexp : float -> int -> float = "caml_ldexp_float"
|
||||
|
|
|
@ -91,6 +91,7 @@ external acos : float -> float = "caml_acos_float" "acos" "float"
|
|||
external asin : float -> float = "caml_asin_float" "asin" "float"
|
||||
external atan : float -> float = "caml_atan_float" "atan" "float"
|
||||
external atan2 : float -> float -> float = "caml_atan2_float" "atan2" "float"
|
||||
external hypot : float -> float -> float = "caml_hypot_float" "caml_hypot" "float"
|
||||
external cos : float -> float = "caml_cos_float" "cos" "float"
|
||||
external cosh : float -> float = "caml_cosh_float" "cosh" "float"
|
||||
external log : float -> float = "caml_log_float" "log" "float"
|
||||
|
@ -104,6 +105,7 @@ external tanh : float -> float = "caml_tanh_float" "tanh" "float"
|
|||
external ceil : float -> float = "caml_ceil_float" "ceil" "float"
|
||||
external floor : float -> float = "caml_floor_float" "floor" "float"
|
||||
external abs_float : float -> float = "%absfloat"
|
||||
external copysign : float -> float -> float = "caml_copysign_float" "caml_copysign" "float"
|
||||
external mod_float : float -> float -> float = "caml_fmod_float" "fmod" "float"
|
||||
external frexp : float -> float * int = "caml_frexp_float"
|
||||
external ldexp : float -> int -> float = "caml_ldexp_float"
|
||||
|
|
|
@ -314,6 +314,13 @@ external atan2 : float -> float -> float = "caml_atan2_float" "atan2" "float"
|
|||
and [y] are used to determine the quadrant of the result.
|
||||
Result is in radians and is between [-pi] and [pi]. *)
|
||||
|
||||
external hypot : float -> float -> float = "caml_hypot_float" "caml_hypot" "float"
|
||||
(** [hypot x y] returns [sqrt(x *. x + y *. y)], that is, the length
|
||||
of the hypotenuse of a right-angled triangle with sides of length
|
||||
[x] and [y], or, equivalently, the distance of the point [(x,y)]
|
||||
to origin.
|
||||
@since 3.13.0 *)
|
||||
|
||||
external cosh : float -> float = "caml_cosh_float" "cosh" "float"
|
||||
(** Hyperbolic cosine. Argument is in radians. *)
|
||||
|
||||
|
@ -337,6 +344,12 @@ external floor : float -> float = "caml_floor_float" "floor" "float"
|
|||
external abs_float : float -> float = "%absfloat"
|
||||
(** [abs_float f] returns the absolute value of [f]. *)
|
||||
|
||||
external copysign : float -> float -> float = "caml_copysign_float" "caml_copysign" "float"
|
||||
(** [copysign x y] returns a float whose absolute value is that of [x]
|
||||
and whose sign is that of [y]. If [x] is [nan], returns [nan].
|
||||
If [y] is [nan], returns either [x] or [-. x], but it is not
|
||||
specified which. *)
|
||||
|
||||
external mod_float : float -> float -> float = "caml_fmod_float" "fmod" "float"
|
||||
(** [mod_float a b] returns the remainder of [a] with respect to
|
||||
[b]. The returned value is [a -. n *. b], where [n]
|
||||
|
|
Loading…
Reference in New Issue