1
+ package com .github .plokhotnyuk .jsoniter_scala .core
2
+
3
+ import org .scalacheck .Arbitrary .arbitrary
4
+ import org .scalatest .matchers .should .Matchers
5
+ import org .scalatest .wordspec .AnyWordSpec
6
+ import org .scalatestplus .scalacheck .ScalaCheckPropertyChecks
7
+
8
+ class NativeMathSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyChecks {
9
+ " NativeMath" should {
10
+ " have multiplyHigh consistent with Math.multiplyHigh" in {
11
+ def check (x : Long , y : Long ): Unit = NativeMath .multiplyHigh(x, y) shouldBe Math .multiplyHigh(x, y)
12
+
13
+ check(Long .MaxValue , Long .MaxValue )
14
+ check(Long .MinValue , Long .MaxValue )
15
+ check(Long .MaxValue , Long .MinValue )
16
+ check(Long .MinValue , Long .MinValue )
17
+ forAll(arbitrary[Long ], arbitrary[Long ], minSuccessful(100000 ))(check)
18
+ }
19
+ " have unsignedMultiplyHigh consistent with Math.unsignedMultiplyHigh" in {
20
+ def check (x : Long , y : Long ): Unit = NativeMath .unsignedMultiplyHigh(x, y) shouldBe unsignedMultiplyHigh(x, y)
21
+
22
+ check(Long .MaxValue , Long .MaxValue )
23
+ check(Long .MinValue , Long .MaxValue )
24
+ check(Long .MaxValue , Long .MinValue )
25
+ check(Long .MinValue , Long .MinValue )
26
+ forAll(arbitrary[Long ], arbitrary[Long ], minSuccessful(100000 ))(check)
27
+ }
28
+ }
29
+
30
+ def unsignedMultiplyHigh (x : Long , y : Long ): Long = { // FIXME: replace by Math.unsignedMultiplyHigh after dropping JDK 17 support
31
+ var r = Math .multiplyHigh(x, y)
32
+ r += y & (x >> 63 )
33
+ r += x & (y >> 63 )
34
+ r
35
+ }
36
+ }
0 commit comments