473,413 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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)
--snip--

temp = (x = xx - 1.0) + 5.5;
temp = (x + 0.5) * log(temp) - temp;

--snip--

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
Jul 5 '08 #1
2 1056
Jay Tee <jt*****@gmail.comwrites:
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)
--snip--

temp = (x = xx - 1.0) + 5.5;
temp = (x + 0.5) * log(temp) - temp;

--snip--

My assumption was this:
x = xx - 1.0
temp = x + 5.5
then later, temp = (x + 0.5) * log(temp) - temp
Looks the same to me (except for the syntax errors from the missing
;s).
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.
You can write exactly the same in PHP as the original. No need to
spit it up. The fact that it comes out differently suggests that
there is some issue about the *types* of the these variables, rather
than the statements that you've show here. C types behave very
differently to PHP types but you don't tell us what types x, xx and
temp are, or how you know it "comes out" differently.

--
Ben.
Jul 5 '08 #2
On Jul 4, 11:00*pm, Ben Bacarisse <ben.use...@bsb.me.ukwrote:
>
You can write exactly the same in PHP as the original. *No need to
spit it up. *The fact that it comes out differently suggests that
there is some issue about the *types* of the these variables, rather
than the statements that you've show here. *C types behave very
differently to PHP types but you don't tell us what types x, xx and
temp are, or how you know it "comes out" differently.

--
Ben.
Thank you :)

I've been wracking my brains for an hour and went ahead and wrote it
the same in PHP (as you suggested) rather than making it more verbose;
turns out I was overthinking things and should have just done it that
way in the first place! Plus I was missing a pair of parens on a
later calculation - probably contributed to my frustration.

On a side note, everything was a float in the function.
Jul 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Allcomp | last post by:
Hello, I have seen something really strange in VB6 If I do a Int ( (5 * 1.2)) , I receive the value 5, but I should receive 6? Is this a bug or something really "normal". I can see that if I...
83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
3
by: Datta Patil | last post by:
Hi , #include<stdio.h> func(static int k) /* point2 : why this is not giving error */ { int i = 10 ; // static int j = &i ; /* point 1: this will give compile time error */ return k; } /*...
31
by: Bjørn Augestad | last post by:
Below is a program which converts a double to an integer in two different ways, giving me two different values for the int. The basic expression is 1.0 / (1.0 * 365.0) which should be 365, but one...
5
by: Tin Gherdanarra | last post by:
Dear mpdls, here is a simple example of an IEnumerable that generates integers: It works, but I have only a vague idea of what's going on. I understand that /yield/ wraps the humble integer...
2
by: righes | last post by:
hi folks, suppose this snipplet: spam = 42 def eggs(): print spam spam = spam + 1
11
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.