New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Argument for ACOS must be in the range [-1, 1] [CORE2970] #3352
Comments
Commented by: @asfernandes It seems the arguments must be verified with some precision. The test try to call asin with a float 1.000000... that's greater than int(1). |
Commented by: @hvlad Should note that 32-bit build works ok while 64-bit build failed. |
Commented by: @hvlad Change in argument verification did nothing as value really greater than 1 and ASIN will return NAN. Seems that x64 performs operations more precise than i86. I have no idea what 0.71939789 and 0.25357501 numbers are but i see that 0.0174532925 is Pi / 180 rounded to 10 digits. SELECT returns 0 Hope this helps. I have no idea why RC2 was OK for you, any chance you used 32-bit build ? |
Commented by: vander clock stephane (arkadia) it's work ok in 64 bit from FB2.0 to FB2.5 RC2 (x64). I never used the 32 bit build. (SIN(41.218463*(0.0174532925)) * SIN(0.71939789)) + (COS(41.218463*(0.0174532925)) * COS(0.71939789) * COS(0.25357501 - (14.528778*(0.0174532925)))) = 0.999999999999994 so it's not possible that FB say that Acos need a value between [1 and -1] because the value (0.999999999999994) is < 1 in other hand but the hint to use PI()/180 instead of 0.01745329252 is good, i will try this ! |
Commented by: @hvlad Its all because of limited precision supported by Firebird. Also, note, that for sin\cos\etc we use CRT which works with double precision type. Another workaround for this your case is to use NUMERIC(11, 6) in table definition. |
Commented by: vander clock stephane (arkadia) it's look now very strange ! i create 2 table first CREATE TABLE TEST ( and second (was already created, our production table) CREATE TABLE GEO_PLACE ( i insert in both table this row (the second table have also lot of other row) i do after to check : Select the Two row are exactly the same (ie only one row returned, or 2 row if Union ALL) now i do Select Work OK now i just replace TEST by GEO_PLACE Select and i have the error Argument for ACOS must be in the range [-1, 1] !! the most important to remembered, the row and the colum definition are EXACTLY THE SAME in the both tables ! |
Commented by: @hvlad Seems GEO_PLACE have another records satisfying your WHERE clause but throwing error in ORDER BY expression |
Commented by: @asfernandes Libc acos manpage says:
So, what about call acos without verify the parameter, but verifying if the returned value was a NaN? |
Commented by: @hvlad > So, what about call acos without verify the parameter, but verifying if the returned value was a NaN? It will just replace one error code by another :) Or do you offer to pass NaN's up to the application as is ? |
Commented by: @asfernandes Vlad, the user said everything was working before. Problem happened only when we start detecting if input in in range -1 to 1 in Windows. So I'd say, MSVC implementation of ACOS detect it in different way (i.e., at some precision). |
Commented by: @hvlad Adriano, i already *run* his sample and argument *really* not in range [1, -1] and ACOS *returns NaN* when i disabled the range check |
Commented by: vander clock stephane (arkadia) actually i correct this bug by doing a round(xxx,15) inside the acos to be sure to be in the [-1..1] boundary ie:
but yes from FB 1.5 to FB 2.5 RC2 it's was working perfectly and in FB 2.5 RC3 then it's start to raise an exception :( |
Submitted by: vander clock stephane (arkadia)
in FB 2.5 RC2 it's work perfectly but in the last FB 2.5 snapshot i have an
error
try this :
CREATE TABLE TEST (
ID VARCHAR(100),
Longitude NUMERIC(11,8),
Latitude NUMERIC(10,8)
);
COMMIT;
INSERT INTO TEST (ID, LATITUDE, LONGITUDE) VALUES
('IT-00298601-00298707-00298781', 41.218463, 14.528778);
commit;
Select
ACOS((SIN(latitude*(0.0174532925)) * SIN(0.71939789)) +
(COS(latitude*(0.0174532925)) * COS(0.71939789) * COS(0.25357501 -
(Longitude*(0.0174532925))))) * 6371
from
TEST
from FB2.0 to FB 2.5 RC2 no problem
in FB2.5 last snapshot in have an error saying that Acos must be between [1 and
-1]
The text was updated successfully, but these errors were encountered: