Jump to content

messy mathematics


clarashymonkey
 Share

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

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

Recommended Posts

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

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

You are about to reply to a thread that has been inactive for 1749 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...