monyet.cc
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
alphacyberranger to Programmer Humor@programming.devEnglish • 2 years ago

Java

lemmy.world

message-square
91
fedilink
538

Java

lemmy.world

alphacyberranger to Programmer Humor@programming.devEnglish • 2 years ago
message-square
91
fedilink
  • @BorgDrone@lemmy.one
    link
    fedilink
    14•
    edit-2
    2 years ago

    You wouldn’t need floor/ceil for that. Casting a double to an int is already predictable as the java language spec explicitly says how to do it, so any JVM will do this the exact same way.

    The floor/ceil functions are simply primitive math operations and they are meant to be used when doing floating point math.

    All math functions return the same type as their input parameters, which makes sense. The only exception are those that are explicitly meant for converting between types.

    • @baseless_discourse@mander.xyz
      link
      fedilink
      2•
      edit-2
      2 years ago

      “predictable” in the sense that people know how it works regardless what language they know.

      I guess I mean “no surprise for the reader”, which is more “readability” than “predictability”

      • @BorgDrone@lemmy.one
        link
        fedilink
        3•2 years ago

        Is there any language that doesn’t just truncate when casting from a float to an int?

        • @baseless_discourse@mander.xyz
          link
          fedilink
          4•
          edit-2
          2 years ago

          As far as I know, haskell do not allow coresion of float to int without specifying a method (floor, ceil, round, etc): https://hoogle.haskell.org/?hoogle=Float±%3E+Integer&scope=set%3Astackage

          Agda seems to do the same: https://agda.github.io/agda-stdlib/Data.Float.Base.html

Programmer Humor@programming.dev

!programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
  • 1.48K users / day
  • 4.17K users / week
  • 10.2K users / month
  • 19.6K users / 6 months
  • 24.3K subscribers
  • 1.52K Posts
  • 56.6K Comments
  • Modlog
  • mods:
  • Feyter
  • adr1an
  • @BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne
  • BE: 0.19.3
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org