Jump to content

Simple question for float result


SubZeroWins
 Share

You are about to reply to a thread that has been inactive for 1308 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Yes, division is tricky, multiplication by the inverse is faster, but..... where do you get the inverse from other than by a division somewhere?

What was more interesting here is that the literals took precedence over the cast to a float. I'm sure many people would have expected that once they had said "I want a float" then the right-hand side of the expression would itself have been implicitly converted to floats.

I wouldn't have assumed so, but I'm old, and I learned programming in a very strange way on a mixture of Forth/Fortran on Honeywells and PDPs, and with those systems you always had to specify the numeric literals to be of the intended form.

 

 

Link to comment
Share on other sites

Never expect something in coding. You know it - or it will not work. 😁

5 is an integer - 2 is an integer -> the expression will use integer math then.

If at least one number is a float ( 5.0/2 ) then float math will be used.

The result goes to the left side of the equation and it will be converted to whatever is needed. But that doesnt affect the calculation.

I set everything manually, by using float or integer numbers or have variables of the correct type or by enforcing the type: (float)intvar

Since I have never seen a documentation of the compiler I can't trust it 😁

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1308 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...