Qbasicnews.com
February 23, 2020, 06:37:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3
  Print  
Author Topic: ROUNDING NUMBERS: Which method do you use? SEE MANY METHODS  (Read 8569 times)
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #15 on: September 02, 2003, 03:37:42 PM »

You spent 20 hours looking for stuff about rounding?!....damn, and I thought I wasted a lot of time...
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #16 on: September 02, 2003, 05:55:41 PM »

Plasma,
Actually I've been investigating the rounding issue for about 3 weeks now. It has become my pet project. If you consider the millions of rounding operations that are performed daily, and some of them erroneously, it is not a trivial matter. I feel that learning about this is not a waste of time. Wouldn't you agree?
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #17 on: September 02, 2003, 06:59:49 PM »

No, I wouldn't. There ain't that much to it. .5 or higher, you round up. Otherwise you round down.

Whatever computers do is just because it's more efficient. For example, 1 KB is not 1000 bytes, but 1024 bytes. It *should* be 1000 bytes, but it's not. Just like 2.5 *should* round to 3, but it doesn't.

I don't think you need to spend 3 weeks to figure this out.
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #18 on: September 02, 2003, 08:20:33 PM »

I disagree with plasma. 1024 bytes has a good reason to be 1024 bytes (^2). But there is no reason why programmers can't round properly in their programs, that's just sloppy. Admittedly rounding normally makes such a small difference that it's not noticeable, but that's no reason to not do it correctly. If you are going to use a method of rounding supplied to you by a computer, you should know how it rounds, and if you don't like it, then make your own rounding function, that's all I'm saying.
Logged

LinkMaster Sab
Member
*
Posts: 82



« Reply #19 on: September 02, 2003, 09:19:56 PM »

It's not too complicated to make your own rounding function, so just make one if it matters Cheesy. I didn't realize there were errors in the code, so now I think I'll start writing one for using regularly.
Logged

 LinkMaster Sab
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #20 on: September 02, 2003, 10:04:44 PM »

Oracle, there is a very good reason: It's faster. Smiley

(And it's not the "programmers" who are sloppy; the rounding is done in the FPU.)
Logged
SCM
Wandering Guru
***
Posts: 311



« Reply #21 on: September 02, 2003, 10:07:07 PM »

It's not errors in the code, it is just a different method intended to avoid bias.  The important thing is knowing how it behaves, so that your program will do what you expect it to do.
Code:

 INT(x)                         rounds to the nearest integer at or below x (the floor)
-INT(-x)                       rounds to the nearest integer at or above x (the ceiling)
 INT(x + .5)                    rounds up for .5 and up down for under .5
 CINT                           rounds .5 to nearest even number otherwise to the nearest number
 SGN(x) * INT(ABS(x) + .5)      rounds .5 away from zero, otherwise to the nearest number


Moneo,
I use the ceiling function for color assignment in my fractals, and I often use the floor (INT) but I can't think of a specific example right now.  They do have their uses, and are recognized mathematical functions.
Logged

hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)

For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #22 on: September 03, 2003, 01:43:55 AM »

Plasma: Faster, eh? I don't doubt you, but don't you think that big software companies should provide the .5 up method as an inbuilt function? Because that's the way much of the world understands rounding...

SCM: INT(RND * num) + 1 Smiley
Logged

Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #23 on: September 03, 2003, 02:26:03 AM »

Is it really that hard to add .5?

Code:
DEF FNround (number) = INT(number + .5)


C'mon, there's no arcsine function either, but nobody's whining about that.
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #24 on: September 03, 2003, 03:34:15 AM »

That doesn't work for negatives Smiley That's the problem that is solved by my function in the very first post, you're a wee bit behind Smiley

And Glenn has an arcsine function Smiley If he's alive, that is Wink
Logged

Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #25 on: September 03, 2003, 09:15:30 AM »

Er, I know that...and I know other people have written arcsine functions. The point is that QB doesn't have EVERY math function, and it shouldn't.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #26 on: September 03, 2003, 04:12:33 PM »

ORACLE and SCM:
You 2 guys have shown that you really understand the issue of various rounding methods, and how to determine which you should use. Thanks for sharing your thoughts and experience.

PLASMA:
Before you go making off-the-wall remarks, you should first read up on the rounding subject, and do some testing of the functions provided in QB with both positive and negative numbers. Then you'll be in a position to voice an opinion. For starters, read the following Microsoft page regarding rounding:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q196652
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #27 on: September 03, 2003, 05:08:59 PM »

MONEO:
I don't think any of my remarks are off the wall. I know how QB's functions work. Just because I didn't waste 3 weeks of my life researching rounding doesn't mean I don't know anything.

(Don't think that because Glenn's not here you get promoted to Captain Badass. Tongue)
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #28 on: September 03, 2003, 06:00:47 PM »

Quote from: "Plasma357"
MONEO:
I don't think any of my remarks are off the wall. I know how QB's functions work. Just because I didn't waste 3 weeks of my life researching rounding doesn't mean I don't know anything.

(Don't think that because Glenn's not here you get promoted to Captain Badass. Tongue)

PLASMA:
First of all, you jumped into this thread 17 days late.
The following are 3 of your remarks which apparently don't show much understanding about rounding nor how QB functions work. Also, your insistent criticism of my spending 3 weeks researching rounding, I thing makes you a better candidate for the "Captain Badass" title.

1) You spent 20 hours looking for stuff about rounding?!....damn, and I thought I wasted a lot of time...

2) There ain't that much to it. .5 or higher, you round up. Otherwise you round down.

3) Is it really that hard to add .5?
*****
Logged
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #29 on: September 03, 2003, 06:16:56 PM »

First of all, I wasn't aware that I had to reply on the first day a message was posted for my opinions to be considered valid.

Second, I find nothing wrong with those statements that you think are "off the wall":

1) is a joke and it's my opinion
2) is the "common" method of rounding
3) was a response to oracle complaining about QB not having a rounding function that follows his rules

And none of those statements have anything to do with QB's functions, so I fail to see how you think that my understanding of QB's functions are lacking. (Thus making you, sir, Captain Badass.)
Logged
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!