This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-04
Channels
- # admin-announcements (1)
- # adventofcode (98)
- # announcements (5)
- # asami (3)
- # babashka (24)
- # beginners (51)
- # bitcoin (3)
- # calva (24)
- # clj-kondo (73)
- # cljdoc (5)
- # cljs-dev (2)
- # clojure (15)
- # clojure-czech (3)
- # clojure-dev (27)
- # clojure-europe (7)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-uk (1)
- # conjure (4)
- # cursive (18)
- # datahike (4)
- # datomic (3)
- # deps-new (7)
- # emacs (1)
- # events (10)
- # fulcro (5)
- # honeysql (4)
- # jackdaw (2)
- # java (13)
- # lsp (85)
- # meander (9)
- # membrane (1)
- # minecraft (1)
- # off-topic (45)
- # re-frame (16)
- # sql (17)
- # tools-deps (10)
- # vscode (9)
- # xtdb (8)
Can I confirm this with others please?
> (doseq [x (range -1073742011 -2147484000 -110)] (when (= 1 (Math/floorMod 1 x)) (println x)))
-2147483691
-2147483801
-2147483911
nil
> (doseq [x (range -2147482742 -2147484000 -110)] (when (= 1 (Math/floorMod 1 x)) (println x)))
-2147483732
-2147483842
-2147483952
nil
The floorMod function is being called with 1
and a large negative number. It should return another large negative number, but occasionally returns 1. It is highly intermittent
If the first argument is -1 instead, then it should be returning -1 every time, but occasionally returns a large positive number instead.
Sounds pretty weird. Which jdk?
I was also able to reproduce on: • mac, java 17, aarch64 • mac, java 1.8.0_192, x86_64 (rosetta)
Well, I've learned these things are usually not the jvm, and that seems like a wide range
I don't suppose you're running on Rosetta or anything
I wonder if it's weirdness related to the ulp bounds and then overflow
Does it happen with StrictMath?
I wonder if it’s sometimes picking the Math.floormod(int int)
method incorrectly with a long and the truncation got you
(time (doseq [x (range -1073742011 -2147484000 -110)] (when (= 1 (Math/floorMod 1 x)) (println x))))
-2147483691
-2147483801
-2147483911
"Elapsed time: 31599.733207 msecs"
(time (doseq [x (range -1073742011 -2147484000 -110)] (when (= 1 (Math/floorMod 1 ^long x)) (println x))))
"Elapsed time: 148.864987 msecs"
=> nil
I’m not surprised that the type hinting is faster. And yes, I think it’s just a case of selecting the wrong function and getting an argument truncated.
It’s not just the second argument. When I gave it a type, and tried it in generative tests again, it failed when it truncated the first argument. I can only avoid the problem when both arguments have explicit types
I wonder if this is https://clojure.atlassian.net/browse/CLJ-2413
Wow CLJ-2413 I'd think would be the case with different runs of the VM. However the non-determinism happening within a single instance is really surprising if that's the case
Does Clojure support calling methods on static
inner classes? A question came up in #java and I can repro the problem: can call .toString()
overridden from Object
but can't any of the methods declared in that inner static
class...
As a general matter, yes, but the privacy levels depend of course
$ cat Foo.java
public class Foo {
public static class Bar {
public Bar () {
}
public void doSomething() {
System.out.println("hello");
}
}
}
$ javac Foo.java
$ clj -Sdeps '{:paths ["."]}'
Clojure 1.11.0-alpha3
user=> (new Foo$Bar)
#object[Foo$Bar 0x54dcbb9f "Foo$Bar@54dcbb9f"]
user=> (.doSomething (new Foo$Bar))
hello
nil
user=>
Thanks for the extra set of eyes @alexmiller -- I'd missed it was a private inner class 😞