* svec_svec_angle - Computes the angle between two SVECs. */
| 504 | * svec_svec_angle - Computes the angle between two SVECs. |
| 505 | */ |
| 506 | Datum svec_svec_angle(PG_FUNCTION_ARGS) |
| 507 | { |
| 508 | SvecType *svec1 = PG_GETARG_SVECTYPE_P(0); |
| 509 | SvecType *svec2 = PG_GETARG_SVECTYPE_P(1); |
| 510 | SparseData left = sdata_from_svec(svec1); |
| 511 | SparseData right = sdata_from_svec(svec2); |
| 512 | double dot, m1, m2, result; |
| 513 | |
| 514 | dot = svec_svec_dot_product( svec1, svec2); |
| 515 | |
| 516 | m1 = l2norm_sdata_values_double(left); |
| 517 | m2 = l2norm_sdata_values_double(right); |
| 518 | |
| 519 | if (IS_NVP(dot) || IS_NVP(m1) || IS_NVP(m2)) PG_RETURN_NULL(); |
| 520 | |
| 521 | result = dot/(m1*m2); |
| 522 | |
| 523 | if (result > 1.0) { |
| 524 | result = 1.0; |
| 525 | } |
| 526 | else if (result < -1.0) { |
| 527 | result = -1.0; |
| 528 | } |
| 529 | |
| 530 | PG_RETURN_FLOAT8(acos(result)); |
| 531 | } |
| 532 | |
| 533 | PG_FUNCTION_INFO_V1( svec_svec_tanimoto_distance ); |
| 534 | /** |
nothing calls this directly
no test coverage detected