×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# compute with floating-point

## compute with floating-point

(OP)
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
Replies continue below

### RE: compute with floating-point

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.

### RE: compute with 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.

### RE: compute with floating-point

resolves the problem with no calculations
Perhaps an EVALUATE to choose the proper redefined variable ?

### RE: compute with floating-point

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.

### RE: compute with floating-point

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

### RE: compute with floating-point

"Compute power is cheap" is no justifiction for sloppy code.

### RE: compute with floating-point

#### Quote (webrabbit):

"Compute power is cheap" is no justifiction for sloppy code.

No, but it sure explains the vast proliferation of it!

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

Razalas

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!