Jump to content

getting 0 with a division into a float type


Rick
 Share

Recommended Posts

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

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

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;

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...