internal write rounds wrong

This is a discussion on internal write rounds wrong within the Fortran forums in Programming Languages category; On 5 sep, 10:12, "Kurt Kallblad" <kurt.kallb...@tele2.se> wrote: > "Leslie Ballentine" <balle...@sfu.ca> wrote in message > > news:g9ph0v$8oq$1 @ morgoth.sfu.ca... > > > > > > > phantasmus <kramer-fah...@arcor.de> wrote: > > : Hi, > > : i want tol display a real number with less decimal places. > > : What i do is an internal write with a format Fx.x like > > : "write(char,form) number" > > > : Normally it works fine but my Fortran rounds the last 5 down. > > : Example: 1.555 is rounded by format F4.2 to 1.55 not to 1.56 > ...

Go Back   Application Development Forum > Programming Languages > Fortran

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #11  
Old 09-05-2008, 05:19 AM
Arjen Markus
Guest
 
Default Re: internal write rounds wrong

On 5 sep, 10:12, "Kurt Kallblad" <kurt.kallb...@tele2.se> wrote:
> "Leslie Ballentine" <balle...@sfu.ca> wrote in message
>
> news:g9ph0v$8oq$1@morgoth.sfu.ca...
>
>
>
>
>
> > phantasmus <kramer-fah...@arcor.de> wrote:
> > : Hi,
> > : i want tol display a real number with less decimal places.
> > : What i do is an internal write with a format Fx.x like
> > : "write(char,form) number"

>
> > : Normally it works fine but my Fortran rounds the last 5 down.
> > : Example: 1.555 is rounded by format F4.2 to 1.55 not to 1.56
> > !!!

>
> > : Has somebody an idea to solve this problem?

>
> > : Thanks a lot

>
> > Why should this be regarded as a problem?
> > The roundoff error is the same, whether rounded up or down.
> > I know that there is an oldfashioned convention to do it the
> > way
> > that you want, but that convention is as arbitrary and
> > unfuctional
> > as the grammatical "rule" against splitting an infinitive.

>
> Leaving the problems with computer's floating numbers:
>
> The rounding metod is not totally arbitrary. To round up in all
> cases can be a problem, e.g. in statistics if a lot of numbers
> end exactly halfway.
>
> In my old textbook in numerical analys the rounding rule was to
> round to an even number if the number ends exactly halfway. E.g.
> 1.555 -> 1.56 and 1.545 -> 1.54 but 1.5451 -> 1.55.
>
> Kurt- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -


That is just one type of rounding. And it is mostly applicable
to situations (like in decimal arithmetic) where the number is
exactly representable.

The problem is solvable (the algorithm to do so has been
published many years ago) but it is not cheap, i.e. it requires
arbitrary precision arithmetic. (I can dig up the reference
if you want.)

Regards,

Arjen

Reply With Quote
  #12  
Old 09-05-2008, 10:08 AM
Kurt Kallblad
Guest
 
Default Re: internal write rounds wrong


"Arjen Markus" <arjen.markus@wldelft.nl> wrote in message
news:89d750dd-5014-41bd-92e9-bf31c246ac9e@s50g2000hsb.googlegroups.com...
> On 5 sep, 10:12, "Kurt Kallblad" <kurt.kallb...@tele2.se>
> wrote:
>> "Leslie Ballentine" <balle...@sfu.ca> wrote in message
>>
>> news:g9ph0v$8oq$1@morgoth.sfu.ca...
>>
>>
>>
>>
>>
>> > phantasmus <kramer-fah...@arcor.de> wrote:
>> > : Hi,
>> > : i want tol display a real number with less decimal places.
>> > : What i do is an internal write with a format Fx.x like
>> > : "write(char,form) number"

>>
>> > : Normally it works fine but my Fortran rounds the last 5
>> > down.
>> > : Example: 1.555 is rounded by format F4.2 to 1.55 not to
>> > 1.56
>> > !!!

>>
>> > : Has somebody an idea to solve this problem?

>>
>> > : Thanks a lot

>>
>> > Why should this be regarded as a problem?
>> > The roundoff error is the same, whether rounded up or down.
>> > I know that there is an oldfashioned convention to do it the
>> > way
>> > that you want, but that convention is as arbitrary and
>> > unfuctional
>> > as the grammatical "rule" against splitting an infinitive.

>>
>> Leaving the problems with computer's floating numbers:
>>
>> The rounding metod is not totally arbitrary. To round up in
>> all
>> cases can be a problem, e.g. in statistics if a lot of numbers
>> end exactly halfway.
>>
>> In my old textbook in numerical analys the rounding rule was
>> to
>> round to an even number if the number ends exactly halfway.
>> E.g.
>> 1.555 -> 1.56 and 1.545 -> 1.54 but 1.5451 -> 1.55.
>>
>> Kurt- Tekst uit oorspronkelijk bericht niet weergeven -
>>
>> - Tekst uit oorspronkelijk bericht weergeven -

>
> That is just one type of rounding. And it is mostly applicable
> to situations (like in decimal arithmetic) where the number is
> exactly representable.
>
> The problem is solvable (the algorithm to do so has been
> published many years ago) but it is not cheap, i.e. it requires
> arbitrary precision arithmetic. (I can dig up the reference
> if you want.)
>
> Regards,
>
> Arjen
>


The background for my post was somebody's comment on the OP's
question: "there is an oldfashioned convention to do it the way
that you want, but that convention is as arbitrary ...". As there
are situations where the rounding is important I thought my
information could be of use. Also note that I started my posting
with "Leaving the problems with computer's floating numbers".

Then thanks for your offer to dig up the reference but you don't
need to do it for me. I have my own routines which cover what I
need.

Kurt

Reply With Quote
  #13  
Old 09-05-2008, 01:13 PM
Gary Scott
Guest
 
Default Re: internal write rounds wrong

Kurt Kallblad wrote:
>
> "Leslie Ballentine" <ballenti@sfu.ca> wrote in message
> news:g9ph0v$8oq$1@morgoth.sfu.ca...
>
>> phantasmus <kramer-fahrer@arcor.de> wrote:
>> : Hi,
>> : i want tol display a real number with less decimal places.
>> : What i do is an internal write with a format Fx.x like
>> : "write(char,form) number"
>>
>> : Normally it works fine but my Fortran rounds the last 5 down.
>> : Example: 1.555 is rounded by format F4.2 to 1.55 not to 1.56 !!!
>>
>> : Has somebody an idea to solve this problem?
>>
>> : Thanks a lot
>>
>> Why should this be regarded as a problem?
>> The roundoff error is the same, whether rounded up or down.
>> I know that there is an oldfashioned convention to do it the way
>> that you want, but that convention is as arbitrary and unfuctional
>> as the grammatical "rule" against splitting an infinitive.
>>

>
> Leaving the problems with computer's floating numbers:
>
> The rounding metod is not totally arbitrary. To round up in all cases
> can be a problem, e.g. in statistics if a lot of numbers end exactly
> halfway.
>
> In my old textbook in numerical analys the rounding rule was to round to
> an even number if the number ends exactly halfway. E.g. 1.555 -> 1.56
> and 1.545 -> 1.54 but 1.5451 -> 1.55.


I think this was more rarely taught. It is an acceptable implementation
to me as long as I know that's what's happening. But I'd like the
choice to select the more commonly taught 5 or greater rounds up.

>
> Kurt



--

Gary Scott
mailto:garylscott@sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Reply With Quote
  #14  
Old 09-05-2008, 02:24 PM
glen herrmannsfeldt
Guest
 
Default Re: internal write rounds wrong

Gary Scott wrote:
(snip, someone wrote)
>> In my old textbook in numerical analys the rounding rule was to round
>> to an even number if the number ends exactly halfway. E.g. 1.555 ->
>> 1.56 and 1.545 -> 1.54 but 1.5451 -> 1.55.


> I think this was more rarely taught. It is an acceptable implementation
> to me as long as I know that's what's happening. But I'd like the
> choice to select the more commonly taught 5 or greater rounds up.


As far as I know, the round to even rule is from statistics,
where the bias might matter. Also, it matters more rounding
data with fewer digits, such as hand recorded data.
(There is also the double rounding problem that might
occur in some statistics problems.)

For numerical analysis problems in double precision there
will usually be enough digits that the bias is pretty small.

-- glen

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:02 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.