Adept Scientific - English
The world's best software for research, science and engineering.
flag arrow
clearclear
 

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKusdedksvnofi
Home
Products
Training
Consultancy
 Buy Online
Downloads
Education
Support
My Adept
International |  About Us |  Contact Us |  Press Room |  Jobs


The Next Steps

• Ask us a question
• Maple Product Tour
• Buy Maple Now
• View Maple Pricing
• Find out about Online Training
• Download a Brochure
• Request a Brochure
• Download a Demo
• Request a Demo
• Meet Our Team
• Read our RSS Feeds

Learn More

Maple Home
Maple 11 Professional
Maple 11 Academic
Maple 11 Student Use
Recorded Online Seminars
FREE Training Resources


MapleNet
Maple T.A.
MapleConnect
BlockImporter for Simulink
BlockBuilder for Simulink
Maple Toolboxes
Maple Rave Reviews
Maple Study Guides
Books about Maple
System Requirements

View Maple 10 in Action
Product Comparison Chart

Latest Information

New Features: Professional
New Features: Academic
The Maple Reporter
The Maple Reporter Online
Numerical Algorithms Group
(NAG)


Service & Support

Maple 10 Training Videos
MaplePrimes, blogs, forums
Elite Maintenance Program
Application Centre
Powertools
Maple User Group (MUG)
Join the Maple User Group
(MUG)

Search the Knowledge Base
Technical Support request

List Archives >  Maple User Group List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MUG] hfarray --> Maple float

Search email archive for  

[MUG] hfarray --> Maple float
Author: Dr George Corliss    Posted: Mon, 05 Aug 2002 09:03:55 -0500

>> From: "Dr. George Corliss" "George.Corliss"

Question: Does Maple do hfarray --> 100 digit
number without rounding?

I am using Maple to check results of a C program
that I know is sensitive to rounding errors.
In pseudocode, the C program:
double x, y;
x = something I construct;
y = f(x); for some function f
write AS BINARY x, y;

In the Maple program, I want something like
Digits := 100;
fd := open (fileName, READ, BINARY);
x := hfarray(1..1);
y := hfarray(1..1);
x := readbytes(fd, x); # Binary read
y := readbytes(fd, y); # Binary read
z := f(x); # Some function f
# Compare y and z
# Expect abs(y - z) / z to be about 10^(-16)

What I WANT is that in Maple, the binary number
x is exactly representable in its hardware floating
point form. Before the function f is evaluated
in Maple's 100 digit arithmetic, I want x to be
converted to the exact 100 digit value of the
binary x. Then I am evaluating f at the exact
argument for f as used by my C program, and z is
the correct value (to nearly 100 digits) of f(x).

I could imagine Maple doing the hfarray --> 100 digit
number exactly.

I could imagine that Maple might take the binary
value, convert it to about 16-18 decimal digits
(possibly committing a rounding error), then
append 82-84 zeros to get a 100 digit number with
rounding errors in about the 16th place.

Does anyone know which (or something else) it is?
How can I tell for certain?

Thanks.

--
Dr. George F. Corliss
Electrical and Computer Engineering
Haggerty Engineering 296
Marquette University
P.O. Box 1881
Milwaukee, WI 53201-1881 USA
"George.Corliss"
Office: 414-288-6599; Dept: 288-6820; Fax: 288-5579

[MUG] Re: hfarray --> Maple float
Author: Maple User Group    Posted: Wed, 7 Aug 2002 16:25:56 -0400 (

>> From: Maple User Group "maple_gr"

-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Tue, 06 Aug 2002 11:50:57 -0700
From: Allan Wittkopf "wittkopf"
Subject: hfarray --> Maple float
To: "maple-list"

In Maple, hardware floats (i.e. hfarrays) contain enough information to
determine the exact 53 bit binary floating point number they correspond to, but
do not represent that number exactly when being displayed, or being converted to
a different datatype (i.e. 100 digit float).

When used as a hardware float (in hardware float only computations) they are of
course used as the exact binary number.

Note that when you look at a hardware float, it actually displays 18 digits,
even though accuracy is only guaranteed to 16 digits for double precision
floats. The two extra digits give sufficient information to determine the exact
53 bit number you need.

The following little routine should do what you need (but I'm sure you could
make it more efficient if you wanted):

hf_to_arb_binary := proc(hf,digits)
local f,s,pow;
Digits := digits;
pow := 1;
s := `if`(hf<0,-1,1);
f := s*hf;
if f>1.0 then
while f*2^pow>1.0 do
pow := pow-1;
end do;
else
while f*2^pow<=1.0 do
pow := pow+1;
end do;
pow := pow-1;
end if;
f := round(f*2^(53+pow));
s*evalf(f/2^(53+pow));
end proc:

Examples:

> evalhf(4/3);
1.33333333333333326

> hf_to_arb_binary(%,100);
1.3333333333333332593184650249895639717578887939453125000000000000000000000\
00000000000000000000000000

> evalhf(4/30000000000);
-9
0.133333333333333338 10

> hf_to_arb_binary(%,100);
0.1333333333333333381909596420663655438887396087466186145320534706115722656\

-9
250000000000000000000000000 10

Notice the last two digits in the hardware float are not what one would expect
from the computation (i.e. the first case we would expect '33' instead of '26')
but that is an artifact of the limited 53 bit representation for hardware
floats. The higher precision number computed from hf_to_arb_binary matches these
results.

Note also that the provided routine could also be used to determine the nearest
hardware float representation of an object, just like evalhf:

> Digits := 20:
> f := evalf(4/3);
f := 1.3333333333333333333

> hf_to_arb_binary(%,100);
1.3333333333333332593184650249895639717578887939453125000000000000000000000\
00000000000000000000000000

> evalhf(%%);
1.33333333333333326

Note the agreement in the '26' and '259...'

- Allan Wittkopf




-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-

Date: Tue, 6 Aug 2002 19:01:32 -0700 (PDT)
From: Peter Montgomery "pmontgom"
To: "maple-list"
Subject: hfarray --> Maple float


I haven't used the BINARY option.
But I suggest that your C program output rational numbers

(mantissa) * 2^(exponent)

(not necessarily in lowest terms). Input these as rational
numbers, and convert them to floating yourself.

The C library function frexp gives mantissa with absolute value
in [1/2, 1). You should be able to multiply this by 2^53,
and output an exact signed integer.


| >> From: "Dr. George Corliss" "George.Corliss"
|
| Question: Does Maple do hfarray --> 100 digit
| number without rounding?
|
| I am using Maple to check results of a C program
| that I know is sensitive to rounding errors.
| In pseudocode, the C program:
| double x, y;
| x = something I construct;
| y = f(x); for some function f
| write AS BINARY x, y;
|
| In the Maple program, I want something like
| Digits := 100;
| fd := open (fileName, READ, BINARY);
| x := hfarray(1..1);
| y := hfarray(1..1);
| x := readbytes(fd, x); # Binary read
| y := readbytes(fd, y); # Binary read
| z := f(x); # Some function f
| # Compare y and z
| # Expect abs(y - z) / z to be about 10^(-16)
|
| What I WANT is that in Maple, the binary number
| x is exactly representable in its hardware floating
| point form. Before the function f is evaluated
| in Maple's 100 digit arithmetic, I want x to be
| converted to the exact 100 digit value of the
| binary x. Then I am evaluating f at the exact
| argument for f as used by my C program, and z is
| the correct value (to nearly 100 digits) of f(x).
|
| I could imagine Maple doing the hfarray --> 100 digit
| number exactly.
|
| I could imagine that Maple might take the binary
| value, convert it to about 16-18 decimal digits
| (possibly committing a rounding error), then
| append 82-84 zeros to get a 100 digit number with
| rounding errors in about the 16th place.
|
| Does anyone know which (or something else) it is?
| How can I tell for certain?

Previous by date: [MUG] Re: Solving equations with radicals, Rafael Espericueta
Next by date: [MUG] Maple 7 under Linux: memory trouble, Jerome BENOIT
Previous thread: [MUG] Bug in print(), Helmut Kahovec
Next thread: [MUG] Maple 7 under Linux: memory trouble, Jerome BENOIT



Ready to buy?

Maple - single user licence
Add to shopping basket
$ 1,895.00
Upgrade to Maple 12 from v11
Add to shopping basket
$ 995.00
Upgrade to Maple 12 from v10 & below
Add to shopping basket
$ 1,395.00

Featured Downloads

What's New in Maple 11 for Professionals
Maple White Paper: Technical Knowledge - An Asset You Can Afford to Lose?
Maple in Electronics Application Pack
Maple in Robotics & Aerospace Application Pack
Maple in Finance Application Pack

Product Reviews

"Without the Maple software, we would have to spend weeks generating the equations of motion for every experiment. Then the chances that we did it right would basically be near zero. There would always be a mistake somewhere. It is very difficult to set up a dynamic motion model by hand."
- Jean-Claude PiedBeouf, Ph.D Manager of Robotics, Canadian Space Agency

"Its very good - highly accurate and easy to use. The speed of Maple allows me to change equations and quickly reintegrate them into the application, so more possibilities can be explored to achieve the precise effect desired."
Shawn Neely, Senior R & D Director for PDI/Dreamworks
adept

Top of the Page

Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2007, Adept Scientific plc.
Site designed and maintained by Adeptise

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055