clarashymonkey Posted July 25, 2019 Share Posted July 25, 2019 Me again! I wonder, is there a more elegant way of scripting the algebraic equation ... x = y / (K - z)? The best i can do is that given ... integer y; // defined as a positive integer elsewhere in the script integer z; // defined as a positive integer elsewhere in the script integer K; // defined as a constant positive integer elsewhere in the script such that K >= y + z ... then ... float x = (float)y / (float)(K - z); ... typecasting the RHS of the equation being (apparently) necessary to avoid z = 0 regardless of the RHS values. Is it just me thinking that looks too ugly to be as good as it gets? Is there a better way? Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted July 25, 2019 Share Posted July 25, 2019 Sadly, no. Integer division is going to give you an integer result. (Rounded towards 0.) One question would be: Do those integers need to be integers? Link to comment Share on other sites More sharing options...
clarashymonkey Posted July 26, 2019 Author Share Posted July 26, 2019 Thank you Wolfie. I thought what you said probably was the case but felt I had to ask. As to whether or not the offending variables need to be integers, I suppose the honest answer is no, except insofar as they represent quantities that are naturally integers and need to serve as divisors in only four instances — to yield the temporary percentage-type logical control variable 'x'. I just hate ugly looking equations, I suppose, but one pays one's money and make one's choice. Thanks again though. At least now when the project's mathematician complains about me butchering her pretty algebra, I can blame SL Link to comment Share on other sites More sharing options...
Recommended Posts
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