changeset 32295:eccbf170743f stable

delaunayn: Add precision loss warning for large int inputs (bug #64658). * delaunayn.m: Add conditional warning for int values larger that flintmax. Move int-to-double conversion after call to __dalaunayn__. Add TODO note about correcting simplex checking calculations to be stable for integer values.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Tue, 12 Sep 2023 22:21:20 -0400
parents b262966c853c
children e35c7b5356b7 0e033c4385a5
files scripts/geometry/delaunayn.m
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/geometry/delaunayn.m	Tue Sep 12 13:15:52 2023 -0400
+++ b/scripts/geometry/delaunayn.m	Tue Sep 12 22:21:20 2023 -0400
@@ -73,11 +73,6 @@
     error ("delaunayn: input PTS must be a 2-dimensional numeric array");
   endif
 
-  ## Avoid erroneous calculations due to int truncation.  See bug #64658.
-  if (isinteger (pts))
-    pts = double (pts);
-  endif
-
   ## Perform delaunay calculation using either default or specified options
   if (isempty (varargin) || isempty (varargin{1}))
     try
@@ -93,6 +88,20 @@
     T = __delaunayn__ (pts, varargin{:});
   endif
 
+  ## Avoid erroneous calculations due to int truncation.  See bug #64658.
+  ## TODO: Large integer values in excess of flintmax can lose precision
+  ##       when converting from (u)int64 to double.  Consider modifying
+  ##       simplex checking to account for large integer math to avoid this
+  ##       problem.
+  if (isinteger (pts))
+    if (any (pts(:) > flintmax ('double')))
+      warning (["delaunayn: conversion of large integer values to ", ...
+                "double, potential loss of precision may result in " ...
+                "erroneous triangulations."]);
+    endif
+    pts = double (pts);
+  endif
+
   ## Begin check for and removal of trivial simplices
   if (! isequal (T, 0))  # skip trivial simplex check if no simplexes