Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ROUNDING, using the CINT, and related information.
#1
At issue is the definition of "rounding". The Quickbasic 4.0 manual for CINT says "Converts a numeric expression to an interger by rounding the fractional part of the expression."

Up until two years ago, I only was aware of one method of rounding. Then I discovered that there were at least eight recognized methods. The CINT function incorporates a variation of the IEEE 754 standard for rounding. The CINT does the following:
2.5 is rounded to 2 instead of 3.
-124.5 is rounded to -124 instead of -125.

Many years ago, this strange behavior was considered by me to be an error in the CINT, so that's why I never use CINT.

As a result, I then wrote a little rounding algorithm, as follows:

ZSIGN = SGN(x)
RESULT = INT(x +.5*ZSIGN)

I was happy with it, and used it for years. Recently I found that certain combinations of numbers give erroneous results, like -123.9 gives -125, and -15.9 gives -17. I have a feeling (totally unfounded) that this is a single precision floating point problem with negative numbers, since the input to the algorithm is single.

Then I took a look at an algorithm by Oracle, which avoids doing arithmetic on negative numbers, as follows:

result = SGN(x) * INT(ABS(x) + .5)

I have tested this little honey every which way from Sunday, and it consistently gives the rounded result which I consider "normal".

If you guys want to see Microsoft's document on the different rounding methods, with a table of methods by programming language, please go to the following link:
http://support.microsoft.com/default.asp...us;Q196652

It'll blow your mind!
*****
Reply
#2
Has anyone read the following page regarding rounding?:
http://support.microsoft.com/default.asp...us;Q196652

If you have, I can't believe no one has any comments. I can't believe you all knew about the 8 methods of rounding, and that you're convinced that your method is fine.
*****
Reply
#3
So, basically, what they're saying is that there's multiple ways of rounding in which to render 'unbiased results'. Unfortuneatley, this really doesn't apply to anything that I would do regarding programming... so.... It's kind of weird that they have multiple ways of rounding, true, but there is really no sort of real-world application for me.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#4
Quote:So, basically, what they're saying is that there's multiple ways of rounding in which to render 'unbiased results'. Unfortuneatley, this really doesn't apply to anything that I would do regarding programming... so.... It's kind of weird that they have multiple ways of rounding, true, but there is really no sort of real-world application for me.
Fine, but you cant ignore the problem forever. When you get into programming in Visual Basic, SQL, and Java and use their "built-in" rounding functions, you will discover the "real world". I'm just trying tro make you aware of the problem in advance.
*****
Reply
#5
And I appreciate it! but my friend tells me that "basic in any form sucks" such as visual basic... basic.... even QBASIC!! NO!!!!! And I don't believe it. I'm living in the past, baby, and it roxors.
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#6
Your friend is a jackass, a nerd, and an idiot all rolled into one. Time for a new friend.
I'd knock on wood, but my desk is particle board.
Reply
#7
Quote:Your friend is a jackass, a nerd, and an idiot all rolled into one. Time for a new friend.

Well said, well said. Only people who don't know how to code would tell you BASIC sux and C is leet.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#8
I added the friend, and talked to him, just for fun.

He doesent know how to code, he just:
"Studies a lot of languages, and because of that [I] know which ones are good and which ones suck"

"BASIC is a bad language because it's too simple"

"BASIC is interpreted"

"BASIC isn't portable"

"BASIC is uppercase, and the variables arent case sensitive"

"Emulation is porting"

*sigh*

WTF is up with everything needing to be portable, screw portability, if I wanted to make stuff for Linux I wouldnt be making stuff for DOS/Windows.

Portability does not make it better, gee...




4n(| fR33B4s1C r0Xx0rs!!111 OMG WTF LOLZZ!!!1111
Reply
#9
Quote:...a jackass, a nerd, and an idiot all rolled into one. Time for a new friend.
Isnt that you? :rotfl: (j/k)

Nova there are real world applications for unimaginable things :wink: So saying "this does have real world application or that doesnt have....blah...blah...." is foolish.

Moneo, interesting info. I just came back so I saw this thread for the first time. Will get back to ya if I have any questions.
Reply
#10
When you're a hobbyist programmer, portability may not be a big concern, but it certainly is very useful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)