[m-rev.] diff: add math.unchecked_sqrt/1

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Nov 30 02:06:44 AEDT 2011


Branches: main, 11.07

Add an unchecked version of math.sqrt/1 to the library.

library/math.m:
 	Add unchecked_sqrt/1.

NEWS:
 	Announce the addition.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.595
diff -u -r1.595 NEWS
--- NEWS	13 Nov 2011 10:53:37 -0000	1.595
+++ NEWS	29 Nov 2011 14:52:52 -0000
@@ -224,4 +224,7 @@
    conforms to the documented behaviour.  The new predicate multi_map.replace/4
    has been added.

+* We have added a version of math.sqrt/1, math.unchecked_sqrt/1, that omits
+  the domain check.
+
  For news about earlier versions, see the HISTORY file.
Index: library/math.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/math.m,v
retrieving revision 1.61
diff -u -r1.61 math.m
--- library/math.m	7 May 2010 03:12:25 -0000	1.61
+++ library/math.m	29 Nov 2011 14:53:35 -0000
@@ -102,6 +102,11 @@
      %
  :- func math.sqrt(float) = float.

+    % As above, but the behaviour is undefined if the argument is less
+    % than zero.
+    %
+:- func math.unchecked_sqrt(float) = float.
+
  :- type math.quadratic_roots
      --->    no_roots
      ;       one_root(float)
@@ -460,39 +465,37 @@
      ( math_domain_checks, X < 0.0 ->
          throw(domain_error("math.sqrt"))
      ;
-        SquareRoot = math.sqrt_2(X)
+        SquareRoot = math.unchecked_sqrt(X)
      ).

-:- func math.sqrt_2(float) = float.
-
  :- pragma foreign_proc("C",
-    math.sqrt_2(X::in) = (SquareRoot::out),
+    math.unchecked_sqrt(X::in) = (SquareRoot::out),
      [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail,
          does_not_affect_liveness],
  "
      SquareRoot = sqrt(X);
  ").
  :- pragma foreign_proc("C#",
-    math.sqrt_2(X::in) = (SquareRoot::out),
+    math.unchecked_sqrt(X::in) = (SquareRoot::out),
      [thread_safe, promise_pure],
  "
      SquareRoot = System.Math.Sqrt(X);
  ").
  :- pragma foreign_proc("Java",
-    math.sqrt_2(X::in) = (SquareRoot::out),
+    math.unchecked_sqrt(X::in) = (SquareRoot::out),
      [thread_safe, promise_pure],
  "
      SquareRoot = java.lang.Math.sqrt(X);
  ").
  :- pragma foreign_proc("Erlang",
-    math.sqrt_2(X::in) = (SquareRoot::out),
+    math.unchecked_sqrt(X::in) = (SquareRoot::out),
      [thread_safe, promise_pure],
  "
      SquareRoot = math:sqrt(X)
  ").
      % This version is only used for back-ends for which there is no
      % matching foreign_proc version.
-math.sqrt_2(X) = math.exp(math.ln(X) / 2.0).
+math.unchecked_sqrt(X) = math.exp(math.ln(X) / 2.0).

  math.solve_quadratic(A, B, C) = Roots :-
      % This implementation is designed to minimise numerical errors;

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list