|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Strange Variable assignment - need translation
I'm trying to decipher this C code and translate it into PHP (long
story). Can anyone help? (xx is a float being passed into the function) temp = (x = xx - 1.0) + 5.5; temp = (x + 0.5) * log(temp) - temp; My assumption was this: x = xx - 1.0 temp = x + 5.5 then later, temp = (x + 0.5) * log(temp) - temp For some reason, I don't think my assumption is correct as the wrong values are coming out of the function. The weird use of parentheses/ assignment operators is throwing me off. Is there a different (a.k.a. more verbose) way to write that snippet? I want to make sure I get this right. Thanks, Jon |
|
#2
|
|||
|
|||
|
Quote:
temp = (x = xx - 1.0) + 5.5; x = xx - 1.0 temp = (xx - 1.0) + 5.5 temp = (x + 0.5) * log(temp) - temp; The thing that may be getting you depending ont he original code is any implicit casting going on between the variables temp, x and xx. Make sure nothing is getting cast to anything less than a float and the log will make the value useless if you are losing precision somewhere in the conversion. If you can test it with a manual calulation break down each calculation step to one pair and display the results to check everything matches what you expect it to be. |
![]() |
| Viewing: Web Development Archives > FAQs > C/C++ > Strange Variable assignment - need translation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|