473,669 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1522

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

Similar topics

4
3948
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 want it to do is like this. example:
1
1664
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
2488
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, the value is rounded towards zero to the nearest integral value." Uh... what? I've hard of "rounding to the nearest integral value", "rounding up", "rounding down", but what in tarnation is "rounded towards
3
28181
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 ); // -1024.2 I was hoping for something either in the string.Format prefix, or
9
4150
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
6639
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 seems to be done like this 3.435 = 3.44 3.445 = 3.44 Dim decNbr1 As Decimal
29
3165
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
2258
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 int(float(a)) except: return 0 The reason for this is the quality of the data from the huge variety of
30
29565
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 expected my_round(2.5) = 2 # Not 3, which is an odd num I'm interested in rounding numbers of the form "x.5" depending upon whether x is odd or even. Any idea about how to implement it ?
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8803
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7407
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2029
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.