• fsxylo@sh.itjust.works
      link
      fedilink
      arrow-up
      25
      ·
      2 years ago

      Also because if you are dealing with a double, then you’re probably dealing with multiple, or doing math that may produce a double. So returning a double just saves some effort.

    • pomodoro_longbreak@sh.itjust.works
      link
      fedilink
      arrow-up
      7
      ·
      2 years ago

      Yeah it makes sense to me. You can always cast it if you want an int that bad. Hell just wrap the whole function with your own if it means that much to you

      (Not you, but like a hypothetical person)

      • RoyaltyInTraining@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        2 years ago

        A double can represent numbers up to ± 1.79769313486231570x10^308, or roughly 18 with 307 zeroes behind it. You can’t fit that into a long, or even 128 bits. Even though rounding huge doubles is pointless, since only the first dozen digits or so are saved, using any kind of Integer would lead to inconsistencies, and thus potentially bugs.

    • karlthemailman@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      How does that work? Is it just because double uses more bits? I’d imagine for the same number of bits, you can store more ints than doubles (assuming you want the ints to be exact values).

  • Marek Knápek@programming.dev
    link
    fedilink
    arrow-up
    27
    ·
    2 years ago

    Makes sense, how would you represent floor(1e42) or ceil(1e120) as integer? It would not fit into 32bit (unsigned) or 31bit (signed) integer. Not even into 64bit integer.

      • 1rre@discuss.tchncs.de
        link
        fedilink
        arrow-up
        2
        arrow-down
        1
        ·
        2 years ago

        I feel this is worse than double though because it’s a library type rather than a basic type but I guess ceil and floor are also library functions unlike toInt

  • maniacal_gaff@lemmy.world
    link
    fedilink
    arrow-up
    22
    arrow-down
    1
    ·
    2 years ago

    It would be kinda dumb to force everyone to keep casting back to a double, no? If the output were positive, should it have returned an unsigned integer as well?

    • baseless_discourse@mander.xyz
      link
      fedilink
      arrow-up
      2
      arrow-down
      2
      ·
      2 years ago

      I think one of the main reason to use floor/ceilling is to predictably cast a double into int. This type signature kind of defeats this important purpose.

      I don’t know this historical context of java, but possibly at that time, people see type more of a burden than a way to garentee correctness? (which is kind of still the case for many programmers, unfortunately.

  • MrGeekman@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    2 years ago

    Try Math.round. It’s been like ten years since I used Java, but I’m pretty sure it’s in there.

  • Bappity@lemmy.world
    link
    fedilink
    English
    arrow-up
    5
    arrow-down
    19
    ·
    2 years ago

    the programming language Java meaning coffee is perfect because, like coffee, it tastes like shit but gets the job done

    • MrGeekman@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      2 years ago

      I think you need to try some lighter-roasted, higher-quality beans which were roasted fairly recently and only grind them a day or so before you use them. There are also different brewing methods and coffee/water ratios that you can try.

      • mestari@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        2 years ago

        I love and consume lots of coffee but I sincerely believe it only tastes good because I associate the taste with the boost it gives. Exactly like cigarettes taste tolerable, good even, when you smoke them regularly.

        • MrGeekman@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          If you don’t know what you’re drinking, it’s probably dark roast. Dark roast is like charcoal compared to light roast.

          The coffee most folks use (i.e. Folgers, Maxwell House) is low-quality coffee made in haste to keep the price low enough for folks to be willing to buy it. They only offer darker roasts because disguise the inferior nature of the beans, or rather the inferior process. The unfortunate truth is that good coffee costs more to process because it takes longer to process and most folks don’t want to spend that much on coffee. So, you get what you pay for.