From ed5cefb4645bbabe92093be9fa80639356e23cb4 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 19 Oct 2009 12:28:25 +0000 Subject: [PATCH] Fix problem of CutValue() function if big precision is used for values output; the problem is caused by previous integration of Windows compatibility patch --- src/PIPELINE/VISU_Extractor.cxx | 40 ++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/PIPELINE/VISU_Extractor.cxx b/src/PIPELINE/VISU_Extractor.cxx index a3d3f211..24f6ecab 100644 --- a/src/PIPELINE/VISU_Extractor.cxx +++ b/src/PIPELINE/VISU_Extractor.cxx @@ -103,15 +103,45 @@ VISU_Extractor vtkFloatingPointType CutValue (vtkFloatingPointType theValue, int theDecimals) { vtkFloatingPointType v = theValue; + +#ifndef USE_OLD_ALGORITHM + // + // VSR 19/10/2009: new algorithm does not use long long type + // + long n1 = 0; + // calculate order of the integral part + while ( v > 1. ) { + v = v / 10.; + n1++; + } + // calculate length of the fractional part + long n2 = theDecimals - n1; + v = theValue; + if ( n2 > 0 ) + while ( n2-- > 0 ) v = v * 10.; + else + while ( n2++ < 0 ) v = v / 10.; + v = floor( (double) v ); + n2 = theDecimals - n1; + if ( n2 > 0 ) + while ( n2-- > 0 ) v = v / 10.; + else + while ( n2++ < 0 ) v = v * 10.; +#else + // + // VSR 19/10/2009: old algorithm uses long long type - + // causes incompatibility with some platforms (Windows?) + // vtkFloatingPointType aDegree = 0.0; - if (abs((long)v) > 1) - aDegree = (long)log10((double)abs((long)v)) + 1; + if (abs((long long)v) > 1) + aDegree = (long long)log10((double)abs((long long)v)) + 1; aDegree = theDecimals - aDegree; - //printf("$$$ 1 v = %.20g , aDegree = %lld \n", v, (long)aDegree); + //printf("$$$ 1 v = %.20g , aDegree = %lld \n", v, (long long)aDegree); aDegree = pow(10, aDegree); - v = ((vtkFloatingPointType)((long)(v * aDegree))) / aDegree; - //printf("$$$ 2 v = %.20g , aDegree = %lld \n", v, (long)aDegree); + v = ((vtkFloatingPointType)((long long)(v * aDegree))) / aDegree; + //printf("$$$ 2 v = %.20g , aDegree = %lld \n", v, (long long)aDegree); +#endif return v; } -- 2.39.2