Skip to content

Commit

Permalink
Fixed CORE-3201 - ATAN2 returns incorrect value for (0, 0).
Browse files Browse the repository at this point in the history
  • Loading branch information
asfernandes committed Feb 3, 2011
1 parent ac6ac97 commit f26d9a4
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lang_helpers/gds_codes.ftn
Expand Up @@ -1458,6 +1458,8 @@ C --
PARAMETER (GDS__cannot_copy_stmt = 335545022)
INTEGER*4 GDS__invalid_boolean_usage
PARAMETER (GDS__invalid_boolean_usage = 335545023)
INTEGER*4 GDS__sysf_argscant_both_be_zero
PARAMETER (GDS__sysf_argscant_both_be_zero = 335545024)
INTEGER*4 GDS__gfix_db_name
PARAMETER (GDS__gfix_db_name = 335740929)
INTEGER*4 GDS__gfix_invalid_sw
Expand Down
1 change: 1 addition & 0 deletions lang_helpers/gds_codes.pas
Expand Up @@ -736,6 +736,7 @@
gds_bad_events_handle = 335545021;
gds_cannot_copy_stmt = 335545022;
gds_invalid_boolean_usage = 335545023;
gds_sysf_argscant_both_be_zero = 335545024;
gds_gfix_db_name = 335740929;
gds_gfix_invalid_sw = 335740930;
gds_gfix_incmp_sw = 335740932;
Expand Down
1 change: 1 addition & 0 deletions src/include/gen/codetext.h
Expand Up @@ -725,6 +725,7 @@ static const struct {
{"bad_events_handle", 335545021},
{"cannot_copy_stmt", 335545022},
{"invalid_boolean_usage", 335545023},
{"sysf_argscant_both_be_zero", 335545024},
{"gfix_db_name", 335740929},
{"gfix_invalid_sw", 335740930},
{"gfix_incmp_sw", 335740932},
Expand Down
6 changes: 4 additions & 2 deletions src/include/gen/iberror.h
Expand Up @@ -759,6 +759,7 @@ const ISC_STATUS isc_request_outdated = 335545020L;
const ISC_STATUS isc_bad_events_handle = 335545021L;
const ISC_STATUS isc_cannot_copy_stmt = 335545022L;
const ISC_STATUS isc_invalid_boolean_usage = 335545023L;
const ISC_STATUS isc_sysf_argscant_both_be_zero = 335545024L;
const ISC_STATUS isc_gfix_db_name = 335740929L;
const ISC_STATUS isc_gfix_invalid_sw = 335740930L;
const ISC_STATUS isc_gfix_incmp_sw = 335740932L;
Expand Down Expand Up @@ -1177,7 +1178,7 @@ const ISC_STATUS isc_trace_switch_user_only = 337182757L;
const ISC_STATUS isc_trace_switch_param_miss = 337182758L;
const ISC_STATUS isc_trace_param_act_notcompat = 337182759L;
const ISC_STATUS isc_trace_mandatory_switch_miss = 337182760L;
const ISC_STATUS isc_err_max = 1121;
const ISC_STATUS isc_err_max = 1122;

#else /* c definitions */

Expand Down Expand Up @@ -1906,6 +1907,7 @@ const ISC_STATUS isc_err_max = 1121;
#define isc_bad_events_handle 335545021L
#define isc_cannot_copy_stmt 335545022L
#define isc_invalid_boolean_usage 335545023L
#define isc_sysf_argscant_both_be_zero 335545024L
#define isc_gfix_db_name 335740929L
#define isc_gfix_invalid_sw 335740930L
#define isc_gfix_incmp_sw 335740932L
Expand Down Expand Up @@ -2324,7 +2326,7 @@ const ISC_STATUS isc_err_max = 1121;
#define isc_trace_switch_param_miss 337182758L
#define isc_trace_param_act_notcompat 337182759L
#define isc_trace_mandatory_switch_miss 337182760L
#define isc_err_max 1121
#define isc_err_max 1122

#endif

Expand Down
1 change: 1 addition & 0 deletions src/include/gen/msgs.h
Expand Up @@ -728,6 +728,7 @@ Data source : @4"}, /* eds_statement */
{335545021, "invalid events id (handle)"}, /* bad_events_handle */
{335545022, "Cannot copy statement @1"}, /* cannot_copy_stmt */
{335545023, "Invalid usage of boolean expression"}, /* invalid_boolean_usage */
{335545024, "Arguments for @1 cannot both be zero"}, /* sysf_argscant_both_be_zero */
{335740929, "data base file name (@1) already given"}, /* gfix_db_name */
{335740930, "invalid switch @1"}, /* gfix_invalid_sw */
{335740932, "incompatible switch combination"}, /* gfix_incmp_sw */
Expand Down
1 change: 1 addition & 0 deletions src/include/gen/sql_code.h
Expand Up @@ -724,6 +724,7 @@ static const struct {
{335545021, -901}, /* 701 bad_events_handle */
{335545022, -104}, /* 702 cannot_copy_stmt */
{335545023, -104}, /* 703 invalid_boolean_usage */
{335545024, -833}, /* 704 sysf_argscant_both_be_zero */
{335740929, -901}, /* 1 gfix_db_name */
{335740930, -901}, /* 2 gfix_invalid_sw */
{335740932, -901}, /* 4 gfix_incmp_sw */
Expand Down
1 change: 1 addition & 0 deletions src/include/gen/sql_state.h
Expand Up @@ -724,6 +724,7 @@ static const struct {
{335545021, "08003"}, // 701 bad_events_handle
{335545022, "XX000"}, // 702 cannot_copy_stmt
{335545023, "22000"}, // 703 invalid_boolean_usage
{335545024, "42000"}, // 704 sysf_argscant_both_be_zero
{335740929, "00000"}, // 1 gfix_db_name
{335740930, "00000"}, // 2 gfix_invalid_sw
{335740932, "00000"}, // 4 gfix_incmp_sw
Expand Down
23 changes: 16 additions & 7 deletions src/jrd/SysFunction.cpp
Expand Up @@ -1072,7 +1072,7 @@ dsc* evlStdMath(thread_db* tdbb, const SysFunction* function, const NestValueArr
if (!v)
{
status_exception::raise(Arg::Gds(isc_expression_eval_err) <<
Arg::Gds(isc_sysf_argmustbe_nonzero) << Arg::Str(function->name));;
Arg::Gds(isc_sysf_argmustbe_nonzero) << Arg::Str(function->name));
}
rc = fbcot(v);
break;
Expand Down Expand Up @@ -1235,22 +1235,31 @@ dsc* evlAsciiVal(thread_db* tdbb, const SysFunction*, const NestValueArray& args
}


dsc* evlAtan2(thread_db* tdbb, const SysFunction*, const NestValueArray& args,
dsc* evlAtan2(thread_db* tdbb, const SysFunction* function, const NestValueArray& args,
impure_value* impure)
{
fb_assert(args.getCount() == 2);

jrd_req* request = tdbb->getRequest();

const dsc* value1 = EVL_expr(tdbb, request, args[0]);
if (request->req_flags & req_null) // return NULL if value1 is NULL
const dsc* desc1 = EVL_expr(tdbb, request, args[0]);
if (request->req_flags & req_null) // return NULL if desc1 is NULL
return NULL;

const dsc* value2 = EVL_expr(tdbb, request, args[1]);
if (request->req_flags & req_null) // return NULL if value2 is NULL
const dsc* desc2 = EVL_expr(tdbb, request, args[1]);
if (request->req_flags & req_null) // return NULL if desc2 is NULL
return NULL;

impure->vlu_misc.vlu_double = atan2(MOV_get_double(value1), MOV_get_double(value2));
double value1 = MOV_get_double(desc1);
double value2 = MOV_get_double(desc2);

if (value1 == 0 && value2 == 0)
{
status_exception::raise(Arg::Gds(isc_expression_eval_err) <<
Arg::Gds(isc_sysf_argscant_both_be_zero) << Arg::Str(function->name));
}

impure->vlu_misc.vlu_double = atan2(value1, value2);
impure->vlu_desc.makeDouble(&impure->vlu_misc.vlu_double);

return &impure->vlu_desc;
Expand Down
2 changes: 1 addition & 1 deletion src/msgs/facilities2.sql
@@ -1,7 +1,7 @@
/* MAX_NUMBER is the next number to be used, always one more than the highest message number. */
set bulk_insert INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUMBER) VALUES (?, ?, ?, ?);
--
('2010-12-17 23:46:00', 'JRD', 0, 704)
('2011-02-02 12:45:00', 'JRD', 0, 705)
('2010-03-15 06:59:09', 'QLI', 1, 531)
--
--('2008-11-28 20:27:04', 'GDEF', 2, 346)
Expand Down
1 change: 1 addition & 0 deletions src/msgs/messages2.sql
Expand Up @@ -811,6 +811,7 @@ Data source : @4', NULL, NULL)
('bad_events_handle', NULL, NULL, NULL, 0, 701, NULL, 'invalid events id (handle)', NULL, NULL);
('cannot_copy_stmt', NULL, NULL, NULL, 0, 702, NULL, 'Cannot copy statement @1', NULL, NULL);
('invalid_boolean_usage', NULL, NULL, NULL, 0, 703, NULL, 'Invalid usage of boolean expression', NULL, NULL);
('sysf_argscant_both_be_zero', 'evlAtan2', 'SysFunction.cpp', NULL, 0, 704, NULL, 'Arguments for @1 cannot both be zero', NULL, NULL)
-- QLI
(NULL, NULL, NULL, NULL, 1, 0, NULL, 'expected type', NULL, NULL);
(NULL, NULL, NULL, NULL, 1, 1, NULL, 'bad block type', NULL, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/msgs/system_errors2.sql
Expand Up @@ -709,6 +709,7 @@ set bulk_insert INSERT INTO SYSTEM_ERRORS (SQL_CODE, SQL_CLASS, SQL_SUBCLASS, FA
(-901, '08', '003', 0, 701, 'bad_events_handle', NULL, 'ERROR')
(-104, 'XX', '000', 0, 702, 'cannot_copy_stmt', NULL, NULL)
(-104, '22', '000', 0, 703, 'invalid_boolean_usage', NULL, NULL)
(-833, '42', '000', 0, 704, 'sysf_argscant_both_be_zero', NULL, NULL)
-- GFIX
(-901, '00', '000', 3, 1, 'gfix_db_name', NULL, NULL)
(-901, '00', '000', 3, 2, 'gfix_invalid_sw', NULL, NULL)
Expand Down

0 comments on commit f26d9a4

Please sign in to comment.