Bankers Rounding

  • Jeff Gray


    Points: 10637

    Hi, I thought I'd chime in with a bit of information.  Axiom and Smalltalk both support rational fractions as data types.

    So one could pass 2/3 as a parameter in either of those languages. 

    It is reasonable to assume that a Turing-complete language such as T-SQL can be programmed to do anything any other language can.  I'm going to have to say that it is possible to pass 2/3 as a parameter in T-SQL. 

    It might not be fast, but it is possible. 

    I'm off to the store to buy some more popcorn.  Hopefully there are no trainwrecks blocking my path.

    Carry on.




  • Sergiy

    SSC Guru

    Points: 109670

    Sorry Jeff,

    you need to take some essential course about computing.

    To pass any value to any function you need to place it in memory.

    Computer's memory (even memory of all computers in the world) is not endless.

    That's why it's impossible to place into memory endless chain of "6" to pass precisely value 2/3.

    Whatever datatype you chose, whatever tricks you apply, you will always pass more or less close representation of 2/3, but never 2/3.

    To have a chance to work out 2/3 (or any another imprecise value) function must be built on concept of representations of imprecise numbers.

    It's definitely not about BR. BR is built on conception where only precise values exist and imprecise values ignored.

    There is no place for 2/3 in this conception.

  • David Jackson


    Points: 6404

    This is fun.

    I read it carefully.

    Especially this:

    Try reading

    I was asked for, and supplied the latest iteration.  That's where you find it.

    What made you change datatype of the input parameter?

    Don't remember?

    Read the topic from the beginning and refresh your memory.

    I've not changed any parameters you idiot.  Lynns Function uses different parameters and always has done.  It was stated in his post. Try reading the 6th message in this thread.  Thats what I've called fn_Bround2

    FLOAT version did not work. And it still does not work.

    You posted examples of wrong results by yourself.

    Correct, and my question was, why are they wrong?  Good grief, you answered it!

    Decimal function does not work as well. Examples posted by me.

    One of them - 50/111.111.

    Again, correct, that's why I posted

    This function does not work in any way.

    Because you cannot build right thing based on the wrong concept.

    I beg to differ

    Dave J
    "I don't know what I don't know."

  • Jeff Gray


    Points: 10637

    Actually, I just need to look at the manual.  It shows clearly that the result of ((4/3)*3) is precisely 1.

    If it were impossible to precisely represent the fraction 2/3 in a computer system, then how is it possible that you can read this post, which:

    1. Was stored on a computer system.

    2. Clearly has the fraction "2/3" as a precise rational number.

    Anyway a more direct response to your response is that a rational fraction can be represented as two integers.  Thus the fraction x/y can be represented as a pair of integers.  To the language that supports this representation, the "parameter" is the pair of integers.  A language is not required to store a fraction as an approximate decimal fraction, unless you say so, I guess.

    I hope your failboat will make it back to shore in one piece.





  • Sergiy

    SSC Guru

    Points: 109670

    I'm not sure if I'm an idiot (very professional behaviour from your side, bravo!), but you are definitely a lier.

    From your link you suggested me to read carefully:

    The corrected Function


    (@p1 DECIMAL(30,20),

    @p2 INT)



    From your post above:

    Do you use actually use double precision in the function?

    Yes. Proof once again you do not read these posts carefully.

    So, what datatype are you actually using for the function parameter?

  • Sergiy

    SSC Guru

    Points: 109670

    Jeff, any practical use of these words you posted to cover your error?

    Do you actually pass formula to functions or just a value stored in some cells in memory?

    Yes, 2/3 can be represented as pair of integers.

    But is it?

    Is it in real life computing?

    Can you write down a function which will accept such representation(s)?

    So what all those ords were for?

  • Jeff Gray


    Points: 10637

    Sorry Sergiy, not plaing that game.  My post was specifically in response to your claim that it is impossible to pass the value 2/3 as a parameter in a programming language.

    I'm not going to debate the practicality of it with you, just pointing out that it is possible.  I've given examples of two languages that support rational fractions as native data types.  Since these languages accept rational fractions as parameters I'd sy my work is done.

    You are simply wrong.  If you'd like to argue about that, you should take it up with the people that have implemented the languages.


    Oh, here's an example of a function:

    Create Function dbo.ConvertFractionToFloat (@X int, @Y int)

    Returns Float as


    Declare @Result float

    Select @Result = convert(float,@X)/convert(float, @Y)

    Return @Result


    select dbo.ConvertFractionToFloat(2,3)




    Oh crap.  Floats are supposed to be most accurate.  Well, the function sucks, but it exists, which satisfies your request.


  • Sergiy

    SSC Guru

    Points: 109670

    Sorry, Jeff,

    you are passing here 2 parameters: int 2 and int 3.

    I don't see anywhere you passing 2/3

    Even if you meant to pass result of that function (forget about imprecision, it does not really matter) then your result is still expressed in FLOAT value having limited capacity and limited precision.

    Result will always be 2/3.

    They may increase FLOAT precision, use 16, 32, 64 bytes for storing this value, but it will not change the fact that limited storage cannot hold unlimited value.

  • Jeff Gray


    Points: 10637

    "Yes, 2/3 can be represented as pair of integers.

    But is it?

    Is it in real life computing?

    Can you write down a function which will accept such representation(s)?"

    Yes I can. And I did.  The function accepts a fraction represented by two integers, per YOUR specification.

    You didn't say that it had to do anything specific, so I just randomly picked the output and logic. so I picked the conversion to float because I knew it would send you off on a another tangent.  (FTFM)

    If you'd like. it could be rewritten to accept a chararacter type, parsing the two integers out.  I'd do it, but I'm working on something a little more important now.


  • Sergiy

    SSC Guru

    Points: 109670

    No, you did not.

    You sent 2 numbers, not a 1 fraction.

    And you never specified it's a fraction.

    Yes, you can rewrite it "to accept a chararacter type, parsing the two integers out". Don't waste your time, I know how to do it and it did it many times.

    But after parsing the string you'll end up with 2 integers and division operator.

    Then you need to apologise to computer and tell him (no. programmer cannot say "it" ) you were joking and those integers are not actually integers. You need to specify some kind of decimal or float datatype with fixed precision. As soon as you did it your "2" becomes "approximately 2" and "3" becomes "approximately 3. You cannot get anyhing precise from an operation on 2 approximations.

    Then. in orser to perform this operation you need FIRST allocate space in memory for the result. Before you do anyhing.

    Limited amount of memory will not let you allocate enough space for 2/3 result. So, you'll rule out this result even before performing any operation.

    As I said, you need some coure on ESSENTIAL computing. Course where say explain that computer parfoms only BYNARY operations. And every value inside a computer must be represented with binary value.

    Sorry, but they still have not invented binary representation for 2/3.

  • David Jackson


    Points: 6404


    Computers are female

    The top six reasons computers must be female:

    6. As soon as you have one, a better one is just around the corner.

    5. No one but the creator understands the internal logic.

    4. Even your smallest mistakes are immediately committed to memory for future reference.

    3. The native language used to communicate with other computers is incomprehensible to everyone else.

    2. The message "Bad Command or File Name" is about as informative as

    "If you don't know why I'm mad at you, then I'm certainly not going to tell you".


    As soon as you make a commitment to one, you find yourself spending half of your paycheck on accessories for it.
    "I don't know what I don't know."

  • Michael Valentine Jones

    SSC Guru

    Points: 64818

    Ways to represent 2/3 exactly:

    0.2 in base 3

    0.4 in base 6

    0.6 in base 9

    0.8 in base 12

    and so on..

    I believe any rational number can be represented as a non-repeating number by choosing the proper base.  The fact that vendors have not chosen to implement number systems in bases other than 2 or 10 does not mean it cannot be done.  It only means that there is little demand for it.


  • Sergiy

    SSC Guru

    Points: 109670

    Unfortunately, computers use base 2.

    When you'll build computer using base 3 don't forget to inform us about this remarkable achievement.


  • Sergiy

    SSC Guru

    Points: 109670

    I use "him" not to be prosecuted for bigamy.

  • Lynn Pettis

    SSC Guru

    Points: 442143

    Been on vacation, but haven't missed any of this.  It offered humor while winding down after a hard day of fun.

    Just thought I'd make sure of something though: Both multiplication and division have the same precedence, true; but 2/3*3 is the same as (2/3)*3 because in the absence of the parens, operators with the same precedence are done left to right, so the division is done before the multiplication.  This is taught in the third grade.

    Haven't taken the time to look at the other thread however, so I hope the work onthe BRound function is going well.


Viewing 15 posts - 346 through 360 (of 374 total)

You must be logged in to reply to this topic. Login to reply