Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this float formula mean?

OK, I was given a formula to determine a float value between 0.0 and 1.0 using i and j (coordinates of a value in a 2D array). I simply want to know exactly what this formula does. It makes no sense to me. I have implemented it in its own function where the int values of i and j are passed as parameters. Can someone provide an explanation? I don't HAVE to understand it, as he gave it to us just to use as is, but I really want to know.

float col = float (((i & 0x08) == 0) ^ ((j & 0x08) == 0));

What exactly is going on here?

like image 406
The Rationalist Avatar asked Jan 16 '13 02:01

The Rationalist


People also ask

What is float formula?

To calculate total float, subtract the task's earliest finish (EF) date from its latest finish (LF) date. It looks like this: LF - EF = total float. Alternately, you can subtract the task's earliest start (ES) date from its latest start (LS) date, like this: LS - ES = total float.

What does float mean in critical path analysis?

Float, sometimes called Slack (float) , is the amount of time an activity, network path, or project can be delayed from the early start without changing the completion date of the project. Total float is the difference between the finish date of the last activity on the critical path and the project completion date.

Why do we calculate float?

Total Float Calculation A project's total float is the difference between the finish date of the last task on the critical path and the project completion date. This will tell you how much total time the critical tasks can be delayed before the entire project misses its completion target.

What is the formula for free float?

Free float is measured by subtracting the early finish (EF) of the activity from the early start (ES) of the successor activity.


1 Answers

The result, if plotted with i,j as the x,y coordinates, will be a checkerboard with squares of 8x8 pixels.

The i & 0x08 and j & 0x08 are just testing a single bit of each axis. That bit will change state every 8 pixels.

The == 0 will convert each result to a boolean, which evaluates to either a 0 or 1. It also inverts the result, but I don't think that's relevant in the overall formula.

The ^ exclusive-or operator will return 0 if the two are the same, or 1 if they're different. That's how you get the checkerboard - the result alternates each time either i or j crosses a boundary.

like image 92
Mark Ransom Avatar answered Oct 27 '22 00:10

Mark Ransom