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;
}