Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004070OCamlOCaml generalpublic2006-07-26 21:262013-09-03 17:16
Reportermottl 
Assigned To 
PrioritynormalSeveritytweakReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version3.08.4 
Target Version4.01.1+devFixed in Version 
Summary0004070: Small tweak for some numeric functions in Pervasives
DescriptionThe functions caml_frexp_float and caml_modf_float in byterun/floats.c could be implemented slightly more efficiently:

Both protect parameter "f", which is not necessary, because it is converted to a C-double before the next allocation anyway, and is not needed afterwards. Instead of "caml_alloc_tuple" it would be more efficient to use "Alloc_small", which would avoid unnecessary function calls. Finally, local value "res" does not need to be protected, because there are no allocations after it has been created.

Here are the alternative functions (untested):

CAMLprim value caml_frexp_float(value f)
{
  CAMLparam0 ();
  CAMLlocal1 (mantissa);
  int exponent;
  value res;

  mantissa = caml_copy_double(frexp (Double_val(f), &exponent));
  Alloc_small(res, 2, 0);
  Field(res, 0) = mantissa;
  Field(res, 1) = Val_int(exponent);
  CAMLreturn (res);
}

CAMLprim value caml_modf_float(value f)
{
#if __SC__
  _float_eval frem; /* Problem with Apple's <math.h> */
#else
  double frem;
#endif
  CAMLparam0 ();
  CAMLlocal2 (quo, rem);
  value res;

  quo = caml_copy_double(modf (Double_val(f), &frem));
  rem = caml_copy_double(frem);
  Alloc_small(res, 2, 0);
  Field(res, 0) = quo;
  Field(res, 1) = rem;
  CAMLreturn (res);
}
Tagspatch
Attached Files

- Relationships

-  Notes
(0009673)
doligez (administrator)
2013-07-02 16:24

Needs careful review and testing.

- Issue History
Date Modified Username Field Change
2006-07-26 21:26 mottl New Issue
2006-08-29 16:59 doligez Status new => acknowledged
2012-09-06 16:43 doligez Target Version => 4.00.1+dev
2012-09-11 16:47 doligez Target Version 4.00.1+dev => 4.00.2+dev
2013-07-02 16:23 doligez Target Version 4.00.2+dev => 4.01.0+dev
2013-07-02 16:24 doligez Note Added: 0009673
2013-07-24 12:01 doligez Target Version 4.01.0+dev => 4.01.1+dev
2013-09-03 17:16 doligez Tag Attached: patch


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker