-
Notifications
You must be signed in to change notification settings - Fork 889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix float/double mismatches in source #150
Comments
A possible solution here is to replace all decimal precision types with a
"real" type that is typedef'd to doubles or floats
…On Sat, Aug 17, 2019, 11:19 Steve Hollasch ***@***.***> wrote:
Lots of places where we're using double constants for use in float
calculations, mixing up our widths when passing parameters, and such. We
need to ensure that our code compiles without any warnings about mixing
precision.
Ideally, it would be good to determine what the impact of float vs. double.
Personally, I prefer double precision, as it's the native precision for
math, and C++ constants, and is frequently faster on platforms that perform
intrinsic computation in double-precision (and thus induce a performance
hit when transforming from and to single-precision.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/RayTracing/InOneWeekend/issues/67?email_source=notifications&email_token=ACNZVKHLGQVU7I527F673U3QFA6MHA5CNFSM4IMQC6HKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HFZNAVQ>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACNZVKCGXMBHY3NHCUYKWFDQFA6MHANCNFSM4IMQC6HA>
.
|
I don't believe that my comment above is warranted. We should pick a precision type and stick with it. I went ahead and created a benchmark. If more data is warranted, To Be Clear |
I also had the idea of I say we convert the entire code base to use simple double-precision floats. Anybody else care to comment? |
If double is not slower than float (single precision) here, I'd vote for just using double everywhere. With float you could get performance benefits when implementing certain parts with SIMD (SSE, AVX) but I don't think we should go there (and I don't know if there are even places where that would work well in any of the code here). |
I think we're starting to lean toward |
From all of this discussion, what I've arrived at is that the only significant difference between This is arguably a benefit because it would much more clearly illucidate the problem. Other than that, I'm not seeing any real argument that isn't aesthetic. My vote is for |
I suspect that adopting double precision may not change the frequency of surface acne. Does it matter if your intersection point is 1e-10 inside the surface versus 1e-100 inside? Should be a simple test to verify, but agree with Trevor that it shouldn't really affect the decision. Sounds like we're agreed on using |
Compiles with no warnings on MSVC 2019 with Warning Level: /W4. - provided CMakeLists.txt (tested only on Windows 10 with MSVC 2019 though, create the project in /build so that it would be ignored by the gitignore) - changed M_PI with a constexpr pi<T>() function - substituted random_double() and drand48() with my own random() function using the Mersenne twister from the standard library - use fstream rather than cout, so that redirecting would not be required - fixed double/float mismatch Removed random.h since it is redundant - I substituted random_double() with my own random() implementation using the Mersenne twister from the standard library. The random_double() in random.h used rand() % (RAND_MAX + 1.0); which is suboptimal (fails multiple statistical tests).
I am for using |
No, see my comment just above yours. Self intersection is not one of the arguments. Instead,
|
As far as the comment above mine goes, What conversion are we talking about? And why would The math libraries that I know of usually provide both single and double precision versions of the functions, notably so does stl.
|
See timing results above. This is not conclusive, but generally true that The code should be most broadly useful, and I know of no platforms that provide only single-precision math libraries, while I know some that provide only double. Regarding constants, yes, I was talking about the C-centric annoyance of having to suffix all numbers with Readers are strongly encouraged to write the raytracing code themselves. The code included in the book is for illustration, and meant to be broadly understood by programmers regardless of their preferred languages. Using |
I thought that the benchmark conclusion was that the "speed up" was due to noise. One also doesn't need to convert between float and double if they keep computations in float. Using double and the code being broadly useful clashes with SIMD and GPU ports, while allowing for no warnings double only libraries integration. Ideally a typedef should be used if the code is to be broadly useful, but that's beyond the point. The I still think it's wasteful using |
Conversion happens in the FPU. Scalar floating point is computed at 64 or 80-bit precision on most architectures. Regardless
|
Fixed in #222 (development branch) |
Lots of places where we're using
double
constants for use infloat
calculations, mixing up our widths when passing parameters, and such. We need to ensure that our code compiles without any warnings about mixing precision.Ideally, it would be good to determine what the impact of
float
vs.double
. Personally, I prefer double precision, as it's the native precision for math, and C++ constants, and is frequently faster on platforms that perform intrinsic computation in double-precision (and thus induce a performance hit when transforming from and to single-precision.The text was updated successfully, but these errors were encountered: