Skip to content

Commit

Permalink
Fix Curve Log2 computation when Float=Double
Browse files Browse the repository at this point in the history
Before, it would end up calling the 64-bit FloatToBits, then letting the result be truncated to 32-bits, and then interpreting some bits of that as exponent. For a double, it ended up using random bits from the significand, rather than the exponent.

Discovered while chasing down mmp#221, though not the cause of it.
  • Loading branch information
mmp committed Oct 13, 2019
1 parent 2aeb128 commit db3fe7d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/shapes/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ bool Curve::Intersect(const Ray &r, Float *tHit, SurfaceInteraction *isect,

Float eps =
std::max(common->width[0], common->width[1]) * .05f; // width / 20
auto Log2 = [](Float v) -> int {
auto Log2 = [](float v) -> int {
if (v < 1) return 0;
uint32_t bits = FloatToBits(v);
// https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog
Expand Down

0 comments on commit db3fe7d

Please sign in to comment.