Hello-
This is a bug in Phantom and will be fixed in a maintenance release. In the mean time, you can use a user defined function as such:
- Code: Select all
# Temporary fix to StrToReal bug
function real MyStrToReal(string s){
string parts = split(s, "E");
if(length(parts) == 1){
return StrToReal(parts[0]);
}else if(length(parts) == 2){
real base = StrToReal(parts[0]);
real exp = StrToReal(parts[1]);
return base * 10.0^exp;
}else{
exception e;
e.SetError("Invalid number: " + s);
e.throw();
}
return 0.0;
}
real r;
disp(MyStrToReal("10.0"));
disp(MyStrToReal("-10.6"));
disp(MyStrToReal("1E+6"));
disp(MyStrToReal("1E-6"));
disp(MyStrToReal("12.421E60"));
disp(MyStrToReal("12.421E-60"));
r = MyStrToReal("12.421E-60")
disp(format("%E", r));
You can put the function in a .fun file and include it whenever you need to do a StrToReal (see 'include' in the Phantom help).
Sorry for any inconvenience this has caused, and I hope this helps!
-John