Skip to content

MDEV-41639 VEC_DISTANCE_COSINE returns 0 for small-magnitude vectors - #5933

Open
Omar-Abdo1 wants to merge 2 commits into
MariaDB:11.8from
Omar-Abdo1:MDEV-41639-cosine-underflow
Open

Omar-Abdo1 wants to merge 2 commits into
MariaDB:11.8from
Omar-Abdo1:MDEV-41639-cosine-underflow

Conversation

@Omar-Abdo1

Copy link
Copy Markdown

https://jira.mariadb.org/browse/MDEV-41639

calc_distance_cosine() multiplied float operands, so squares of components
below ~1e-23 underflowed to 0 in float precision before being accumulated
into the double variables. The result became 0/0 = NaN.

Fix: convert the operands to double before multiplying.

A test with small orthogonal, opposite and identical vectors is added in
mysql-test/main/vector_small_cosine.test.

Omar-Abdo1 and others added 2 commits October 20, 2026 17:40
calc_distance_cosine() multiplied float operands in float precision, so
squares of components below ~1e-23 underflowed to 0, and the result
became NaN. Convert the operands to double before multiplying.
@CLAassistant

CLAassistant commented Oct 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Omar-Abdo1

Copy link
Copy Markdown
Author

buildbot/amd64-windows-packages failed in the “MTR - HashiCorp Vault” step with Could not parse mysqld --help: thread-p before any test ran. This looks like a worker/infrastructure problem, unrelated to this change.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants