GingerRobot
Staff Alumni-
Posts
4,082 -
Joined
-
Last visited
Everything posted by GingerRobot
-
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
It seems so. When raising a negative number to a fractional power, if the denominator is even, you get a complex answer. If it is odd, you get a real answer. I can't seem to figure out how it all works to be honest though. -
Just with a quick glance, it looks to me like you're mising a couple of things. Firstly, when you call your Mileage function, you pass in two variables: $start and $end. Unless these are global variables, they are undefined within your function, x. Second, if you're function returns a value, you need to do something with the returned value, its no use just making a call to the function. Generally, you would either assign the returned value to a variable, or echo the returned value. Edit: Beaten to it, but thought id post anyway, what with the additional information.
-
Id go along with that. Flashy website, but ultimately, a rubbish host.
-
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Unfortunately i dont think its quite that simple. For example, you should get answers with the following inputs of: (-1)^1/2 = i (-1)^1/3 = -1 (-1)^1/4 = 0.70711+0.7011i - the numerical values are actually sin(45 degrees) if you're interested At present, your code returns i for all of these inputs. I might take a look later and see if i can come up with a solution. I dont think it's going to be easy though. -
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Appears to work fine for positive bases Barand, but once we move into negatives, i think there are some problems. For instance, if you input (-1)^0.5 you get 1; though the root of -1 is i. -
Defining multiple values in an IF statement.
GingerRobot replied to woolyg's topic in PHP Coding Help
Either: <?php if($fileType != 'jpg' && $fileType != 'gif' && $fileType != 'png'){ echo "Wrong file type"; } else { echo "Right file type"; } ?> Or: <?php $extensions = array('jpg','gif','png'); if(!in_array($fileType,$extensions){ echo "Wrong file type"; } else { echo "Right file type"; } ?> Using an array will make things more manageable. Though it is also likely to be less efficient since you have to use the in_array() function. However, we're talking tiny differences here, so its largely irrelevant. -
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Check here Note the use of the word "positive" Also read this (which explains why rational powers of negative reals are troublesome) Hmm, yes i do follow that. I notice that the method shown there is to use the fractional power inside the bracket, and the integer power outside. That would indeed mean that if the denominator were even, you could not find a real solution if the base is negative. However, im fairly sure there is nothing to say that you have to use the fractional power inside the bracket. As far as i know (x^(1/b))^a is identical to (x^b)^(1/a). Definitely one for my maths teacher i think. -
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Indeed. It just seems very odd to me that by choosing a different but equal fraction, you can find a real solution to the question. -
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
Im now confusing myself the more i think about it. I was looking at this example: (-4)^(3/2) now, 4^(3/2) is 8. Since you do (4^3)^(1/2) = 64^(1/2) = 8. Following the same pattern, you get ((-4)^3)^(1/2) = (-64)^1/2. So you get non-real anwer (8i if you're interested). So far, that makes sense. However, isn't 6/4 the same as 3/2? Couldn't you therefore do (-4)^(6/4)? (-4)^(6/4) = ((-4)^6)^(1/4) = 4096^(1/4) = 8. How can it be that by changing the power to an equal fraction, you can solve with a real answer? Perhaps there is a huge flaw in my maths somewhere. -
[SOLVED] Fractional Indices and Negative Numbers
GingerRobot replied to GingerRobot's topic in PHP Coding Help
I think you're pretty much there Barand. Was just doing a bit of investigating with my calculator. However, it does seem that you do not always end up with complex numbers. For example, (-1)^2.1 is non-real, whilse (-1)^2.2 equals -1. I've no idea why that happens, im just off to google. Might have to ask my maths teacher when im back at 6th form. Ill save it for a particularly boring lesson when a change of subject is much needed. -
[SOLVED] PHP not pulling from phpMyAdmin starting at "0"...
GingerRobot replied to ShootingBlanks's topic in PHP Coding Help
This loop: while($row = mysql_fetch_assoc($getCategories)){ echo '<option value="'.$row['cat_id'].'"'; if ($row['cat_id'] == $row_getDocument['cat_id']) { echo ' selected="selected"'; } echo '>'.$row['cat_name'].'</option>'; } -
Yeah, i had noticed you could round. Thanks to you both for the help and information. I'll mark this as solved.
-
[SOLVED] PHP not pulling from phpMyAdmin starting at "0"...
GingerRobot replied to ShootingBlanks's topic in PHP Coding Help
Well, without any more code, im going to take a stab in the dark. Im going to assume that you are calling the mysql_fetch_row(or similar) function prior to your loop. If you take a look at the manual, you will notice that by calling any of these functions, you also move the internal array pointer. This basically means that next time you call the function, you are already on the second row. Hope that helps. -
The output you get is exactly as you would expect. In your first set of code, you firstly create an array, with an element which is the string 'bob' in it. This has the key 0 - since you did not specify a key. You then add a new element to your array, which has the key 'bob' and value 65433. You therefore have two elements in you array - one of which has the value bob, whilst the key of the other is bob. In the second code sample, you only put the element with the key bob and the value 65433. Therefore, when you print out the contents, there is only one thing in your array. It's not an issue of declaration - in both cases you implicitly define your array by placing elements into it. It is simply a case of the number of elements you put into it. I hope that makes more sense than i think it might.
-
I don't particularly like to ask another question relating to the workings of the maths functions in PHP in the same day, however, ive just noticed something which seems rather odd. It seems to me like PHP cannot calculate a negative number raised to a non-integer power. For example, this code: <?php for($x=-10;$x<=10;$x++){ echo $x.'=>'.pow($x,(2/3)).'<br />'; } ?> Produces: -10=>-1.#IND -9=>-1.#IND -8=>-1.#IND -7=>-1.#IND -6=>-1.#IND -5=>-1.#IND -4=>-1.#IND -3=>-1.#IND -2=>-1.#IND -1=>-1.#IND 0=>0 1=>1 2=>1.58740105197 3=>2.08008382305 4=>2.51984209979 5=>2.92401773821 6=>3.30192724889 7=>3.65930571002 8=>4 9=>4.32674871092 10=>4.64158883361 Using pow($x,1.5) or anything similar produces results like those above. Any thoughts?
-
I think you'd go for $_SERVER["QUERY_STRING"] - since this contains only the text after the ? It always seems like an ugly method to me though - as jesirose said, you're better off putting the variable in the URL and retrieving it from the GET array.
-
Makes sense. Thanks for the information. Presumably PHP doesn't have a 'table' of special values then? Otherwise you would expect : echo sin(pi()); To produce 0? Or have i misunderstood?
-
Daniel: I suppose its possible. I can't believe im the first person ever to notice, however. Tibberous: Yeah, ok, Anything divided by 0 is undefined, im with you there. However, im talking about dividing 0 by something else - which should be 0. Perhaps my original statement should have been "0 divided by any other non-zero number is 0"
-
I've just noticed that this statement: echo tan(deg2rad(360)); Produces an answer of -2.44921270764E-016. Yet if i put tan(360) into my calculator, the answer is 0 - which i always thought it was. Perhaps ive missed some crucial part of maths somewhere along the line. As far as i know, tanx = sinx/cosx. So tanx = 0/1 (where x is 360). It was my understanding that 0 divided by anything is 0. Is this not the case? Any information would be appreciated. Edit: Ive just noticed that the problems seem to stem from the sin function. sin(deg2rad(360)) gives -2.44921270764E-016, rather than 0. Yet sin(deg2rad(0) does give the answer as 0. Any thoughts?
-
Well presumably your php.ini file is set to report notices, otherwise it wouldn't be reporting them. I thought the default was changed at some point to include notices, but apparently not. Anyways, you should be using: E_ALL & ~E_NOTICE To not report notices, but still report other errors.
-
[SOLVED] Preventing [spaces] on a subject or message.
GingerRobot replied to Gath's topic in PHP Coding Help
Using regular expressions just to remove the whitespace on the end is a bit overkill anyway. Using the trim function would be more efficient. -
It would be far easier to get someone else to test it with you! After all, you'll never be 100% sure it is working until it is fully tested.
-
If you're going to be storing all of that information about each user, you might as well stick it all in the same table. I would guess the only possible need for a separate table would be a table listing all of the types of instant messengers - you'd then store an ID of the IM client in the user table. Personally, im not sure id even bother with that.
-
And the problem is?
-
Well i would guess, the problem is that you echo roomNum regardless of wether or not there was a match. Try: if ( $roomMatch > 0 ) # found existing room name { $roomNum = ociresult($room,"ROOM_NUM"); echo "<br>room_num of match: " . $roomNum; }else{ echo "No matching room found"; }