diff options
Diffstat (limited to 'src/com/android/gallery3d/util/GalleryUtils.java')
-rw-r--r-- | src/com/android/gallery3d/util/GalleryUtils.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index 47beb2d09..9c08deaa5 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -333,4 +333,23 @@ public class GalleryUtils { throw new AssertionError(); } } + + public static void doubleToRational(double value, long[] output) { + // error is a magic number to control the tollerance of error + doubleToRational(value, output, 0.00001); + } + + private static void doubleToRational(double value, long[] output, double error) { + long number = (long) value; + value -= number; + if (value < 0.000001 || error > 1) { + output[0] = (int) (number + value + 0.5); + output[1] = 1; + } else { + doubleToRational(1.0 / value, output, error / value); + number = number * output[0] + output[1]; + output[1] = output[0]; + output[0] = number; + } + } } |