HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk arithmethic - calculation error Risc/UX11....
Operating System - HP-UX
1832993
Members
4091
Online
110048
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2004 08:13 PM
07-04-2004 08:13 PM
We discovered a calculation error in our SAP system. This happens only on Risc based machines while Itanium is ok (all HP-UX machines).
When running the small example below we get result:
s=9,9999999999999956E-01, x=2, y=3
on Risc machines (ux 11.11) while we get the correct answer on ia64 (ux 11.23):
s=0,0000000000000000E+00, x=3, y=3
ABAP (SAP native) program language
report zastest1 .
data: s type f.
data: t type f.
data: x type p.
data: y type p.
s = 1000.
t = 1000.
s = frac( log10( s ) ).
x = trunc( log10( t ) ).
y = log10( t ).
write: / 's= ', s.
write: / 'x= ', x.
write: / 'y= ', y.
NB! type p is an integer type
I would like to test this outside SAP and would need something similare to run as a shell/awk-script.
/Tor-Arne
When running the small example below we get result:
s=9,9999999999999956E-01, x=2, y=3
on Risc machines (ux 11.11) while we get the correct answer on ia64 (ux 11.23):
s=0,0000000000000000E+00, x=3, y=3
ABAP (SAP native) program language
report zastest1 .
data: s type f.
data: t type f.
data: x type p.
data: y type p.
s = 1000.
t = 1000.
s = frac( log10( s ) ).
x = trunc( log10( t ) ).
y = log10( t ).
write: / 's= ', s.
write: / 'x= ', x.
write: / 'y= ', y.
NB! type p is an integer type
I would like to test this outside SAP and would need something similare to run as a shell/awk-script.
/Tor-Arne
I'm trying to become President of the state I'm in...
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2004 01:31 AM
07-05-2004 01:31 AM
SolutionThose results are the same, within the constraints of the datatype used.
Some (many!) numbers do NOT have an exact representation in floating point, there will be an error in the final bit.
The simplest, silly example of this is the classic 3*(1/3).
1/3 = 0.333333333...
3*(1/3) = 0.9999999999... or 1.0 ?
The exact hardware implementation of the floating point (ieee or native) defines how the cookie crumbles.
It is up to the application to select the right datatype and to appropriate rounding or truncation operations for that datatype.
Just round the log resulst to 10 digits or so and you'll see the same 'expected' result in both cases.
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2004 02:45 AM
07-06-2004 02:45 AM
Re: awk arithmethic - calculation error Risc/UX11.11
I'm not sure how many signifcant digits are in SAP's floating point. One of the things that I noticed about machines from the old 16 bit days was that HP old 16 bit machines had less bits in the mantissa of the floating point number than the INTEL machines. So if the log10(10) to come out 2.999999999 would not be that suprising.
In the old FORTRAN days, floating point numbers with standard precision was only good to 6 digits.
For fun try the following example by hand....
Represent .1 as a floating point number.
So like the example of 1/3 you have a repeating fraction (this time a binary one). So as has been pointed out some numbers can't be represented in base 10 math and some numbers that you wouldn't normally suspect, cannot be represented in binary.
In the old FORTRAN days, floating point numbers with standard precision was only good to 6 digits.
For fun try the following example by hand....
Represent .1 as a floating point number.
So like the example of 1/3 you have a repeating fraction (this time a binary one). So as has been pointed out some numbers can't be represented in base 10 math and some numbers that you wouldn't normally suspect, cannot be represented in binary.
"Only he who attempts the absurd is capable of achieving the impossible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2004 08:39 AM
07-08-2004 08:39 AM
Re: awk arithmethic - calculation error Risc/UX11.11
Thank you both for the answer. It put me on the track, though it wasn't a direct answer to my question for an awk program where I could check the precision.
I found in SAP's documentation of "ABAP Numeric Types" a description of the danger of using floating point in such business transactions...
Here is some of their own brief statements of their datatypes:
1)
Rule: If you want to calculate "down to the last penny", you should use the type P.
P is a type with specified precision.
Type P is typically used for sizes, lengths, weights and sums of money.
2)
Use floating point arithmetic if you need a very large value range or you are making decimal calculations, but be aware of the following features of floating point arithmetic.
--- then there is a description who try to show what you already told me, though they explain it in a more complex way---.
3)
---And in there some warnings to the programmer---.
You should also note that multiplication using powers of 10 (positive or negative), is not an exact operation.
---and---
You should also note that multiplication using powers of 10 (positive or negative), is not an exact operation.
QED
From our business we got a report about a price error on approx. 200 Euro on 1 order...
We have created a temporary workaround until they come up with a fix.
The small program example was an extract of the original SAP std. program where we saw the error happened after debugging.
I'm still trying to convince SAP, among others by pointing to their own documentation.
That's part of life or what...
P.S.
I found that awk have the log-function and that it is natural logarithm. From this I can get to the base-10 representation.
/Tor-Arne
I found in SAP's documentation of "ABAP Numeric Types" a description of the danger of using floating point in such business transactions...
Here is some of their own brief statements of their datatypes:
1)
Rule: If you want to calculate "down to the last penny", you should use the type P.
P is a type with specified precision.
Type P is typically used for sizes, lengths, weights and sums of money.
2)
Use floating point arithmetic if you need a very large value range or you are making decimal calculations, but be aware of the following features of floating point arithmetic.
--- then there is a description who try to show what you already told me, though they explain it in a more complex way---.
3)
---And in there some warnings to the programmer---.
You should also note that multiplication using powers of 10 (positive or negative), is not an exact operation.
---and---
You should also note that multiplication using powers of 10 (positive or negative), is not an exact operation.
QED
From our business we got a report about a price error on approx. 200 Euro on 1 order...
We have created a temporary workaround until they come up with a fix.
The small program example was an extract of the original SAP std. program where we saw the error happened after debugging.
I'm still trying to convince SAP, among others by pointing to their own documentation.
That's part of life or what...
P.S.
I found that awk have the log-function and that it is natural logarithm. From this I can get to the base-10 representation.
/Tor-Arne
I'm trying to become President of the state I'm in...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP