Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compute with floating-point

Status
Not open for further replies.

cbmstr

Programmer
Feb 9, 2009
4
Hello,

the COMPUTE example below with a floating-point is much faster(about 1:4) than without one. Can somebody explain it ? It´s depending on which compiler there are used ?

COMPUTE decimal = amount * (10 ** (dcml * -1)) + 0.0E+00)

decimal PIC S9(12)V(6) COMP-3.
amount PIC S9(18) COMP-3.
dcml PIC 9(04).

Regards

cbmstr
 
What do you mean "with floating point"? Do you mean with that "+ 0.0E+00" in the equation? In any case, floating point will probably use the numeric co-processor, which is much faster for doing exponential calculations. Comp-3 is not a native format for pc's and does not enhance the speed of calculations. Use Comp, Comp-4 or Comp-5, (all binary) except when you are doing exponentiation, then use Comp-1 or Comp-2, which are floating point.
 
It appears that you are simply adjusting the decimal point position. Defining the data as display and redefining it with the decimal point in the desired location resolves the problem with no calculations. If dcml has more than about three possible values, this apporce is a bit clumsy, but is still likely faster and will result in no rounding errors. If dcml is > 6, you will have erroneous results in any case.
 
resolves the problem with no calculations
Perhaps an EVALUATE to choose the proper redefined variable ?
 
Evaluate is what I was thinking of. According to Micro Focus' documentation, an Evaluate on one numeric variable with contiguous or nearly contiguous values is highly efficient.
 
Or one might imagine a decimal arithmetic package that understands how to detect a mantissa that normalizes to 1 and adjust the scale of the intermediate result, bypassing any additional exponentiation.

That same decimal arithmetic package might also similarly recognize a multiplication where the multiplier or multiplicand, or a division where the divisor, normalizes to a power of 10 and adjust the scale of the intermediate result.

But that all depends on how you measure efficiency. Will the OP ever recover the computational time spent researching this and posing the question?

Tom Morrison
 
webrabbit said:
"Compute power is cheap" is no justifiction for sloppy code.

No, but it sure explains the vast proliferation of it![sad]

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top