Rick Posted October 25, 2010 Share Posted October 25, 2010 OK, feeling dumb. What am I missing with this. The following is setting ratio to 0.0 instead of 0.25. float ratio = 200 / 800; Quote Link to comment Share on other sites More sharing options...
Paul Posted October 25, 2010 Share Posted October 25, 2010 Because its an integer division. Try 200.0f / 800.0f Quote Intel Core i7 975 @ 3.33GHz, 6GB ram, GTX 560 Super OC, Windows 7 Pro 64bit Link to comment Share on other sites More sharing options...
Mumbles Posted October 25, 2010 Share Posted October 25, 2010 Because its an integer division. Try 200.0f / 800.0f Well, that's the fastest solution. float a = 200, b = 800, ratio = a / b; would also work because by the time 'a' and 'b' are reached they are floats. In Rick's case it evaluates the constants (as ints) as 0 and then stores the result as ratio Quote LE Version: 2.50 (Eventually) Link to comment Share on other sites More sharing options...
Rick Posted October 25, 2010 Author Share Posted October 25, 2010 I could have sworn at one point in C++ it would do the conversion for me, but maybe I've been using .NET to long. Thanks guys. Quote Link to comment Share on other sites More sharing options...
Roland Posted October 25, 2010 Share Posted October 25, 2010 The compiler just needs a little hint on whats going on. So this will do the trick float ratio = 200.0 / 800; ration will get the value 0.25 as excepted. Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Rick Posted October 25, 2010 Author Share Posted October 25, 2010 Yeah I was just using those as hardcoded examples. In the actual code those are variables that are from TextureWidth/Height functions. I casted them both to float and they work now. I could have sworn it used to know that. Quote Link to comment Share on other sites More sharing options...
Canardia Posted October 25, 2010 Share Posted October 25, 2010 If you use double instead of float, you get 5 times faster speed (you can verify it with GNU/VS2008 by timing the execution of a few float vs double calculations): double ratio = 200.0 / 800.0; Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.