MantisBT - VTK
View Issue Details
0015557VTK(No Category)public2015-06-27 11:372015-08-13 10:11
Tsutomu Ikegami 
T.J. Corona 
normalminorhave not tried
closedfixed 
6.0.0 
 
TBD
incorrect functionality
0015557: vtkFunctionParser gives wrong results for numeric literals
The vtkFunctionParser wrongly parses numeric literals with exponent notation. For example, "3.0e+01" is parsed as 31.0 = 3.0e01 + 01. I have confirmed the phenomena on VTK version 6.2.0.

----- sample code in python -----
import vtk
f = vtk.vtkFunctionParser()
f.SetFunction("3.0e+01")
print f.GetScalarResult()

=> 31.0
---------------------------------

I noticed that only the '(\d)e-(\d)' case is treated specially in vtkFunctionParser.cxx:l.1542, but I have no graceful idea to fix it.
No tags attached.
Issue History
2015-06-27 11:37Tsutomu IkegamiNew Issue
2015-08-07 12:58T.J. CoronaAssigned To => T.J. Corona
2015-08-12 10:57T.J. CoronaNote Added: 0034974
2015-08-12 10:57T.J. CoronaStatusbacklog => closed
2015-08-12 10:57T.J. CoronaResolutionopen => fixed
2015-08-12 21:28Tsutomu IkegamiNote Added: 0034979
2015-08-12 21:28Tsutomu IkegamiStatusclosed => backlog
2015-08-12 21:28Tsutomu IkegamiResolutionfixed => reopened
2015-08-13 10:11T.J. CoronaNote Added: 0034986
2015-08-13 10:11T.J. CoronaStatusbacklog => closed
2015-08-13 10:11T.J. CoronaResolutionreopened => fixed

Notes
(0034974)
T.J. Corona   
2015-08-12 10:57   
Scientific notation with a unary plus operator now behaves correctly. Additionally, the unary plus operator has been added to vtkFunctionParser. For more information, see

https://gitlab.kitware.com/tjcorona/vtk/commit/1f890b9bfa5e45cdfd748f9147225907c980da00 [^]
(0034979)
Tsutomu Ikegami   
2015-08-12 21:28   
Thank you for the correction. Please allow me to add a quick patch. This corrects "3.0E-01" case, which is also parsed by atof() function at line 2034.

--- vtkFunctionParser.cxx.orig 2015-08-13 10:21:58.000000000 +0900
+++ vtkFunctionParser.cxx 2015-08-13 10:22:47.000000000 +0900
@@ -1563,7 +1563,7 @@
           !((this->Function[i] == '-' || this->Function[i] == '+') &&
             (this->IsElementaryOperator(this->Function[i-1]) ||
              this->Function[i-1] == '(' ||
- (this->Function[i-1] == 'e' && i > 1 &&
+ ((this->Function[i-1] == 'e' || this->Function[i-1] == 'E') && i > 1 &&
               isdigit(this->Function[i-2])))) &&
           !(this->Function[i] == '.' &&
             (i+1 < this->FunctionLength) &&
(0034986)
T.J. Corona   
2015-08-13 10:11   
Thanks! This addition has been made. For more information, see

https://gitlab.kitware.com/vtk/vtk/commit/c5c1880ab61b37fa931f60ad359a0f1e4ee308c6 [^]