From c8d482d77e284a00dfd2d52fe40ed44d76edc365 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Thu, 25 Oct 2007 08:55:07 +0000 Subject: [PATCH] cleaner (?) char2float --- Numeric/Numeric.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Numeric/Numeric.cpp b/Numeric/Numeric.cpp index 4445f1fb40..6a47f3b313 100644 --- a/Numeric/Numeric.cpp +++ b/Numeric/Numeric.cpp @@ -1,4 +1,4 @@ -// $Id: Numeric.cpp,v 1.33 2007-08-31 09:18:16 geuzaine Exp $ +// $Id: Numeric.cpp,v 1.34 2007-10-25 08:55:07 geuzaine Exp $ // // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle // @@ -434,14 +434,15 @@ double triangle_area(double p0[3], double p1[3], double p2[3]) char float2char(float f) { // f is supposed to be normalized in [-1, 1] - f = (f > 1.) ? 1. : (f < -1.) ? -1 : f; + f = (f > 1.) ? 1. : (f < -1.) ? -1. : f; // char is in [-128, 127] - return (char)(-128 + (f + 1.)/2. * 255); + return (char)(-128 + (f + 1.) / 2. * 255); } float char2float(char c) { - return -1. + (float)(c + 128)/255. * 2.; + float f = c; + return -1. + 2. * (f + 128.) / 255.; } double InterpolateIso(double *X, double *Y, double *Z, -- GitLab