• Tale (unregistered)

    It's quaint how you think there is one thing called "mathematical rounding" that stands in opposition to "bankers rounding". There are more than just two ways to round, and all of them are mathematical, even random rounding.

  • (cs) in reply to nerd4sale
    nerd4sale:
    Jibble:
    You're saying the number 1/2 can't be exactly represented in binary?
    You can, obviously. Everybody knows that binary values are 0, File Not Found and 1.

    FRACTION_NOT_FOUND

  • Norman Diamond (unregistered) in reply to JimM
    JimM:
    anonymous:
    That doesn't explain why the penny should still be the smallest countable unit of US currency.
    It's like that by definition. Anyone who wants to redefine currency should feel free to do so - but good luck getting the rest of the world to go along with you for it ;)
    The US stopped minting half-cents in 1857. I'm not sure when US copper coins became legal tender, or if half-cents were included at the time. As far as I can tell, if half-cents didn't become legal tender before 1965, they did when the Coinage Act of 1965 gave legal tender status to all US coins.

    But the rest of the world doesn't have to go along with it. Most countries accept US paper money for some purposes, but most do not accept US coins.

  • SmartAlec (unregistered) in reply to foo AKA fooo

    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.

  • facilisis (unregistered) in reply to SmartAlec
    SmartAlec:
    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.
    gcc (4.1.2 as that's all I have access to right now) on x86_64 generates almost[1] identical assembly code for
    int sgn(int x) { return 1 - 2 * (x < 0); }
    and
    int sgn2(int x) { return x >= 0 ? 1 : -1; }
    With no optimisation, both of them include a conditional branch, and with -O2 neither of them do. Therefore, even if you care about literally every CPU cycle, the more readable version should be preferred.

    Admittedly I don't know if Delphi is as smart, but if not then you can assume that anyone using it doesn't care about that level of optimisation anyway.

    [1] The only difference is that without optimisation, the sense of the branch and the corresponding "if" / "else" chunks are reversed.

  • Paul Neumann (unregistered) in reply to RandomGuy
    RandomGuy:
    I think it's ok to teach round-ties-away-from-zero in schools. Basically, you don't need to teach children about things such as numerical drift. But what children also should learn in school, is that they never learn the whole truth in school. But calling that "mathematical rounding" is absurd. Actually, calling the (elementary school) subject "mathematics" is exaggerated, as it is mostly "calculation" what children learn ...
    Agreed; true; Strongly agreed; Agreed; I've always heard it called Arithmetic at that level.
  • foo AKA fooo (unregistered) in reply to SmartAlec
    SmartAlec:
    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.
    How do you think "Integer (Value < 0)" is implemented? Just because it doesn't look like a branch/cmov doesn't mean there isn't one.
  • foo AKA fooo (unregistered) in reply to facilisis
    facilisis:
    Admittedly I don't know if Delphi is as smart, but if not then you can assume that anyone using it doesn't care about that level of optimisation anyway.
    Don't know much about current Delphi versions either, but WRT its predecessor, Borland Pascal, your statement is quite wrong. It had a terrible to non-existent optimizer, yet many of its users did care very much about optimization. Their solution? Of course, rewrite everything time-critical (and many things non-critical) in inline assembler code (good thing it supported this). It got especially funny if their hand-optimized solutions actually ran slower than the code generated by the non-optimizing compiler, yet they felt so clever and smug about it, as could be witnessed regularly on usenet ...
  • anonymous (unregistered) in reply to foo AKA fooo
    foo AKA fooo:
    SmartAlec:
    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.
    How do you think "Integer (Value < 0)" is implemented? Just because it doesn't look like a branch/cmov doesn't mean there isn't one.
    That reminds me of the comment I read where someone stated that their program didn't use any division operations but it included a printf("%d", i);. Assuming that i could potentially be larger than 9, how exactly did they think that worked?
  • foo AKA fooo (unregistered) in reply to anonymous
    anonymous:
    foo AKA fooo:
    SmartAlec:
    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.
    How do you think "Integer (Value < 0)" is implemented? Just because it doesn't look like a branch/cmov doesn't mean there isn't one.
    That reminds me of the comment I read where someone stated that their program didn't use any division operations but it included a printf("%d", i);. Assuming that i could potentially be larger than 9, how exactly did they think that worked?
    Oh, it's quite possible to implement that without division. -- And this site is exactly right for posting such code ...
  • Neil (unregistered)

    Even after all this, neither rounding function works because they return a double which can only exactly represent 0, 25, 50 or 75 cents.

  • anonymous (unregistered) in reply to foo AKA fooo
    foo AKA fooo:
    anonymous:
    foo AKA fooo:
    SmartAlec:
    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.
    How do you think "Integer (Value < 0)" is implemented? Just because it doesn't look like a branch/cmov doesn't mean there isn't one.
    That reminds me of the comment I read where someone stated that their program didn't use any division operations but it included a printf("%d", i);. Assuming that i could potentially be larger than 9, how exactly did they think that worked?
    Oh, it's quite possible to implement that without division. -- And this site is exactly right for posting such code ...
    If the resulting code is actually faster than using the division operation and works correctly for any valid integer i, I'd be impressed. Bonus points if it works for signed integers.
  • foo AKA fooo (unregistered) in reply to anonymous
    anonymous:
    foo AKA fooo:
    anonymous:
    foo AKA fooo:
    SmartAlec:
    You're replacing simple multiplication with a branch, or at best a conditional move. Not a terrible thing in and of itself, but in the context of pessimizing a small snippet of code, this is not making things better.
    How do you think "Integer (Value < 0)" is implemented? Just because it doesn't look like a branch/cmov doesn't mean there isn't one.
    That reminds me of the comment I read where someone stated that their program didn't use any division operations but it included a printf("%d", i);. Assuming that i could potentially be larger than 9, how exactly did they think that worked?
    Oh, it's quite possible to implement that without division. -- And this site is exactly right for posting such code ...
    If the resulting code is actually faster than using the division operation and works correctly for any valid integer i, I'd be impressed. Bonus points if it works for signed integers.
    I think you misunderstood me ... :)
  • dummzeuch (unregistered) in reply to Walky_one

    Yes, it's years later but I would like to add that Delphi (at least since Delphi 2007) has had a SimpleRoundTo function that implements the "Round half away from zero" algorithm. SimpleRoundTo(12.5, 0) = 13, SimpleRoundTo(11.5, 0) = 12.

Leave a comment on “Fixing Delphi”

Log In or post as a guest

Replying to comment #:

« Return to Article