boostorg / boostorg/math

Can boost::math::float_distance be sped up?

Open
#359 5 comments 0 reactions 0 assignees Claimed by @mborland View on GitHub
Dominant language
C++
Stars
374
Forks
264
Avg merge
1d 23h
Merged PRs (30d)
17

Description

In the AGM PR, I have found that ~90% of the runtime is spent computing float distances. However, at least for `float` and `double`, the following trivial modification drops the runtime to a negligible fraction of the total runtime:

```
int32_t fast_float_distance(float x, float y) {
static_assert(sizeof(float) == sizeof(int32_t), "float is incorrect size.");
int32_t xi = *reinterpret_cast(&x);
int32_t yi = *reinterpret_cast(&y);
return yi - xi;
}

int64_t fast_float_distance(double x, double y) {
static_assert(sizeof(double) == sizeof(int64_t), "double is incorrect size.");
int64_t xi = *reinterpret_cast(&x);
int64_t yi = *reinterpret_cast(&y);
return yi - xi;
}
```

It seems like `boost::math::float_distance` is considerably more general than this, but can we dive through a happy path to extract performance in the trivial cases?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.