473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

numeric rounding thought



With all the discussion about numbers here and particularly in regards
to prePEP concerning decimal data types got me wondering about how
numbers are handled when it comes to rounding. And if that can be
improved.

My thought/question is, is it possible to have a numeric varable
where weather or not it's value has been rounded, and which way, is
persistent?

For example using 2 bits to represent this you would have something
like the following for each value of n:

n00 # value not rounded, an exact amount
n01 # rounded down
n10 # rounded up
n11 # rounded even, sum of oppositely rounded numbers

I was originally thinking base 10 rounding, but realized this would
apply to base 2 numbers also.

If the numbers retain their rounding status, would it be possible to
use that in the following ways.

Addition:
n00 = n00 + n00
n01 = n00 + n01 or n01 = n11 + n01
n10 = n00 + n10 or n10 = n11 + n10
n11 = n01 + n10 or n11 = n11 + n11

The rules of multiplication would be the same as addition.

Subtraction would reverse the bits of the second term and then be the
same as addition.

Division ..... ? I haven't thought past this point yet. But I don't
think it would be too hard to figure out. This would set a rounding
bit depending on the outcome and the rounded status of the varables
used.

Anyway, this is just an idea and I was wondering if something like
this would help in cases like representing 0.1 in binary or 1/9 in
decimal?

Could something like this reduce the trailing digits that sometimes
appear by allowing the number to be rounded in the appropriate
direction? or be used to indicate repeating decimals?

Would this maintain a significant degree of accuracy over a large
numbers of operations within a given precision?

Are there systems that have used something like this before?

And of course this may be too hardware/compiler dependant to
implement. Or it may take up more memory or slow things down too much
to be worth while.

_Ron (Just thinking out loud.)
Ronald R. Adam
ra****@tampabay.rr.com

Jul 18 '05 #1
0 1509

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gezeala 'Eyah' Bacu\361o II | last post by:
hey guys..need your help on this.. i have a plpgsql function where in i compute numeric values for my php scripts.. my problem is my function just won't round some numbers properly.. what i...
1
by: Rajesh Kumar Mallah | last post by:
Hi, How come numeric(10,2) accepting value 10.011 and truncating the .001 part ? Shudnt' it be complaining , i am not sure. Regds Mallah.
4
by: Daniel Billingsley | last post by:
I'm trying to figure out what happens when I cast a double with (int)... does it round or drop the decimal part? MS says: "When you convert from a double or float value to an integral type,...
3
by: Ken Durden | last post by:
Is it possible to force positive values to have the + sign prefixed on them? double f1 = 1024.2; double f2 = -1024.2; string.Format( "{0:F}", f1 ); // +1024.2 string.Format( "{0:F}", f2 );...
9
by: Agnes | last post by:
Where I can find the tutorial about numeric function.. e.g x = 15/6, i need to get the result (2) but not (2.5) also get the reminder y = 15/6 , i can get the result (3) Thanks
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
29
by: Marco | last post by:
Hello, I have : float f = 36.09999999; When I do : char cf; sprintf(cf,"%0.03lf", f); I get : 36.100
4
by: Doug Gray | last post by:
Folks, I am looking for a fast but most importantly a bullet proof method to pass and NMEA data stream (GPS output) ascii numeric strings. The best I can offer is: def fint(a): try: return...
30
by: bdsatish | last post by:
The built-in function round( ) will always "round up", that is 1.5 is rounded to 2.0 and 2.5 is rounded to 3.0. If I want to round to the nearest even, that is my_round(1.5) = 2 # As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.