Comments (4)
All such "stupid" inputs containing spaces can be easily solved by removing all spaces and making the program more secure. The following routine is very suitable for this purpose:
{
Deletes all occurrences of sub-String Needle from String HayStack AND returns
the resulting String. HayStack is returned unchanged If it does NOT contain
Needle. The search is Case sensitive.
}
Function DelAllStr(CONST Needle, Haystack: String): String;
// http://delphidabbler.com/url/csdb.
Var
StartIdx: Integer;
Begin
Result:= Haystack;
StartIdx:= SysUtils.AnsiPos(Needle, Result);
While StartIdx > 0 Do
Begin
Delete(Result, StartIdx, Length(Needle));
StartIdx:= SysUtils.AnsiPos(Needle, Result);
End;
End;
A call like this solves all these problems:
CONST
Space = β β;
. . .
S:= DelAllStr(Space, S);
. . .
Andreas
from neslib.multiprecision.
We are entering a bit of a grey area here. Usually, whitespace is used to separate multiple values. In that case it shouldn't be ignored. Also, entering whitespace in "normal" floating-point literals is not allowed in Delphi.
I will look into this this weekend if I have some time. In general, I want to follow the same conventions as the Delphi RTL. So if the standard StrToFloat function does not accept whitespace, then neither should the DoubleDouble/QuadDouble version.
One way to make stupid users less stupid is to not accept stupid inputsπ
from neslib.multiprecision.
OK Erik, agree with you. But then such an input as follows should not be accepted at all, because thereby an apparent result - namely a wrong one - comes out:
Y/X:
----
X = 1E - 1
Y = - 2
MPA_Float = -20 ---> Correct
QuadDouble = -2.00000000000000000000000000000000000000000000000000000000000000
DoubleDouble = -2.0000000000000000000000000000000
Thanks
Andreas
from neslib.multiprecision.
I made some changes to make the parsing behave more like Delphi's StrToFloat
:
- When using the implicit String operator (as in
X := '- 2'
), it will raise an EConvertError exception now when the input is invalid, so it will not create invalid output. - Leading and trailing whitespace is accepted (as in
StrToFloat
). - Other whitespace is regarded as a separator and stops parsing at that point. So
X := '1 2'
is parsed successfully as1
, butX := '- 2
' results in an error because'-'
by itself is not a valid number.
This will probably not account for all possible (parsing) errors, but it is more closely in line with what Delphi's StrToFloat
does.
Let me know if there are any other cases where the behavior differs from the StrToFloat
behavior.
from neslib.multiprecision.
Related Issues (9)
- Handling of integers HOT 2
- QuadDouble not working with Delphi XE5 HOT 1
- Tanh produces incorrect results HOT 2
- Incorrect conversion from strings with 'E0' suffix HOT 1
- Incorrect conversion from strings with 'E+1' suffix HOT 1
- Problems with numerical overflows/underflows in some functions HOT 5
- Incorrect string parsing of QuadDouble HOT 3
- Support of Type Extended for Win32 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neslib.multiprecision.