Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mathematical rounding
Message
De
31/01/2005 18:14:35
 
 
À
31/01/2005 12:43:52
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00982326
Message ID:
00982533
Vues:
22
>Hi to all,
>
>Here is the controversy:
12.345   -> 12.3
>         -> 12.4
In my opinion, the first one (12.3) is the correct 'mathematical rounding' (to 1 decimal here). However, some colleagues say the second one is correct.
>
>Please, tell me that I'm correct! ;)

Natural definition for natural round in a algebric group:
This is the standard definition
 on base 10 ( a algebric group )
 any element is a polynomial as:
x=N(k)*10^K+...+N(0)*10^0+N(-1)*10^-1+N(-2)*10^-2....
the ROUND(x,h) is
ROUND(x,h)=N(k)*10^K+...+N(0)*10^0+N(-1)*10^-1+N(-2)*10^-2....N'(-h)*10^(-h)
where 
    N'(-h)=N(-h)   if 0<=N(-h)<5  ( base/2) ( 0,1,2,3,4 ) 5 weights
    N'(-h)=N(-h)+1 if 5<=N(-h)    ( base/2) ( 5,6,7,8,9 ) 5 weights

but this is a simplified definition for b=10.
If the base is b=2*i+1 ( odd )
the definition is not therefore immediate.

I prefer this:
It is more syntetic and general ( for base b odd or even is ) definition is:
    N'(-h)=N(-h)+CARRY(x+x,-h)
where CARRY(x+x,-h) is the carry at power -h of the x+x addition.

example in base 3:
ROUND(12.112,1)=12.2
ROUND(12.111,1)=12.1
You have to observe a point:
* this is not a valid rule 
ROUND(x,h)=ROUND(ROUND(x,h+1),h)
then:
ROUND(12.345,1)=12.3<>12.4=ROUND(12.35,1)=ROUND(12.345,2),1)
This roundig rule don't minimize the computation error,
with 5 round down the average error is the same,
but with this you have the same probability
of apply or not apply the CARRY() value.

Fabio
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform