Maybe its just the fact my head feels like mush at the moment, but i cant think of a nice algorithm that will calculate fractions for GDI displaying.

Im writing a Plot routine (x,y) to plot data points. If my Drawing Box is say 200x200 pixels, and i want to display UNSIGNED BYTES (max 255). I hit a limit at 200, where the below ratio == 1.

I *was* using this equation To determing the Data Height For the Plot:

The Problem is when MAX_Y_DATA gets larger than Delta_Pixels (Physical # of y pixels to use). When it does, it becomes ZERO (integer math), and a i get nothing displayed... :rolleyes:

I can not use the FPU or MMX to solve this. All i have to work with is the standard registers (including esi, edi, and ebx). As well, it should work for SIGNED numbers as well as UNSIGNED.

This is something im not familiar with for PROTECTED mode. My FPU knowledge came from a 16 bit AoA.. :rolleyes:. I would imagine it would be easier to solve if i used the above equation on the FPU and casted back to an integer when done, but then again im unsure of the correct way of doing this as well.....

So in recap,

1) Anyone know of a good Integer method to handle fractions * integers that result > 0.

2) Anyone know of the

Thanx for any advice you can provide!

:alright:

NaN

:stupid:

Im writing a Plot routine (x,y) to plot data points. If my Drawing Box is say 200x200 pixels, and i want to display UNSIGNED BYTES (max 255). I hit a limit at 200, where the below ratio == 1.

I *was* using this equation To determing the Data Height For the Plot:

**Plot_y = DataPoint * ( Delta_Pixels_Y / MAX_Y_DATA )**The Problem is when MAX_Y_DATA gets larger than Delta_Pixels (Physical # of y pixels to use). When it does, it becomes ZERO (integer math), and a i get nothing displayed... :rolleyes:

I can not use the FPU or MMX to solve this. All i have to work with is the standard registers (including esi, edi, and ebx). As well, it should work for SIGNED numbers as well as UNSIGNED.

**However, I *could* use the FPU on one condition: The FPU contents (what ever is in it) must be fully saved and restored.**This is something im not familiar with for PROTECTED mode. My FPU knowledge came from a 16 bit AoA.. :rolleyes:. I would imagine it would be easier to solve if i used the above equation on the FPU and casted back to an integer when done, but then again im unsure of the correct way of doing this as well.....

So in recap,

1) Anyone know of a good Integer method to handle fractions * integers that result > 0.

**or**2) Anyone know of the

__Proper__way of fully storing and restoring the FPU (including any status, and control bits)?Thanx for any advice you can provide!

:alright:

NaN

:stupid:

Here is a sample of what im talking about: The max in this case is 190. Here you see it as column 3. Every data point is being represented at a 1:1 ratio. If I add a data point 191 in the array, it will all go zero, as discussed above in my first post.

You could use a log scale.

1000

100

10

1

1000

100

10

1

Hi NaN, one trick to remember with computer maths is to leave division towards the end of a caluclation as this reduces precision errors.

This is espicially true of integer maths, so try the following simple change:

As for 2) I don't know but would be interested to hear how its done.

This is espicially true of integer maths, so try the following simple change:

**Plot_y = ( DataPoint * Delta_Pixels_Y ) / MAX_Y_DATA**As for 2) I don't know but would be interested to hear how its done.

**Plot_y = ( DataPoint * Delta_Pixels_Y ) / MAX_Y_DATA**

This works fine.

You can avoid the division loop with one of the two following tricks:

1) Use a precomputed table of division by MAX_Y_DATA.

In your case, if Delta_Pixels_Y and MAX_Y_DATA are given, you can use a precomputed table of Delta_Pixels_Y*MAX_Y_DATA.

Ex:

DataPoint is between 0 and 255.

DataTable[0] = 0*Delta_Pixels_Y / MAX_Y_DATA

DataTable[...]

DataTable[255] = 255*Delta_Pixels_Y / MAX_Y_DATA

Now, you can have Plot_Y in one lookup table:

DataTable

This is especially efficient if you have to display a HUGE WAVE sample.

2) Use a multiplication by the inverse.

Simply compute INTCOEF = 65536/MAX_Y_DATA.

Now, if you want to have the result of A/MAX_Y_DATA, simply:

(A *INTCOEF) / 65536

This method is efficient when you need to keep the fraction.

JC

Thanx for the suggestions so far...

While i got things padded out for this simple case.. there will be more complex cases coming.. It would be nice to know how to properly save and restore the FPU, if anywone knows how to? In the future i plan to suport Real4 and Real8 data sets, so weather i like it or not, i will eventually need to use the FPU...

Thanx again for your help everyone.

:alright:

NaN

**Eoin,**Yup, I changes the order of op's so as you suggested, and it now works to 255. Thanx. My head must have been mush not to have seen this.**bdjames**, Sorry it wont protray the data fairly, as well, i would need to use the FPU to determine the log if i wanted to.. Thanx anyways.**MCoder**, Your suggestions are good ones, but I failed to say that that all three terms can be changing, so its impractical to make static arrays.While i got things padded out for this simple case.. there will be more complex cases coming.. It would be nice to know how to properly save and restore the FPU, if anywone knows how to? In the future i plan to suport Real4 and Real8 data sets, so weather i like it or not, i will eventually need to use the FPU...

Thanx again for your help everyone.

:alright:

NaN

No one know how to safely store and restore the FPU's contents in Masm32??

Is it safe to use the same instructions as 16 bit FPU commands?

Thanx... NaN

Is it safe to use the same instructions as 16 bit FPU commands?

Thanx... NaN

Is it safe to use the same instructions as 16 bit FPU commands?

Thanx for the Link bitRAKE... this is way better than the pdf's...

:alright:

NaN

:alright:

NaN

The FXSAVE and FXRSTORE instructions seem very fast for 512 bytes!

Im not familiar with these commands?? They are not FPU are they?

It's actually like an FPU-SSE instruction. You can also use FSAVE/FNSAVE and FRSTOR. :)