Skip to content

Commit fc9996a

Browse files
adinauerclaude
andcommitted
fix(android): Adapt floor math from Guava
Use Apache-licensed Guava LongMath floor division logic for SentryMath and restore the matching third-party attribution. Keep floorMod implemented through floorDiv so it matches Math.floorMod for negative divisors too. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e9f735e commit fc9996a

2 files changed

Lines changed: 55 additions & 8 deletions

File tree

THIRD_PARTY_NOTICES.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@ limitations under the License.
3434

3535
---
3636

37+
## Google Guava — LongMath (Apache 2.0)
38+
39+
**Source:** https://github.com/google/guava/blob/v33.0.0/guava/src/com/google/common/math/LongMath.java<br>
40+
**License:** Apache License 2.0<br>
41+
**Copyright:** Copyright (C) 2011 The Guava Authors
42+
43+
### Scope
44+
45+
The Sentry Java SDK includes adapted floor division logic from Guava's `LongMath` class to support older Android API levels. The code resides in `io.sentry.vendor.SentryMath`.
46+
47+
```
48+
Copyright (C) 2011 The Guava Authors
49+
50+
Licensed under the Apache License, Version 2.0 (the "License");
51+
you may not use this file except in compliance with the License.
52+
You may obtain a copy of the License at
53+
54+
http://www.apache.org/licenses/LICENSE-2.0
55+
56+
Unless required by applicable law or agreed to in writing, software
57+
distributed under the License is distributed on an "AS IS" BASIS,
58+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59+
See the License for the specific language governing permissions and
60+
limitations under the License.
61+
```
62+
63+
---
64+
3765
## FasterXML Jackson — ISO8601Utils (Apache 2.0)
3866

3967
**Source:** https://github.com/FasterXML/jackson-databind<br>
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Adapted from https://github.com/google/guava/blob/v33.0.0/guava/src/com/google/common/math/LongMath.java
3+
*
4+
* Copyright (C) 2011 The Guava Authors
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
119
package io.sentry.vendor;
220

321
final class SentryMath {
@@ -6,16 +24,17 @@ private SentryMath() {}
624

725
static long floorDiv(final long x, final long y) {
826
final long quotient = x / y;
9-
final long remainder = x % y;
10-
return remainder != 0 && hasDifferentSigns(x, y) ? quotient - 1 : quotient;
11-
}
27+
final long remainder = x - y * quotient;
1228

13-
static long floorMod(final long x, final long y) {
14-
final long remainder = x % y;
15-
return remainder != 0 && hasDifferentSigns(x, y) ? remainder + y : remainder;
29+
if (remainder == 0) {
30+
return quotient;
31+
}
32+
33+
final int signum = 1 | (int) ((x ^ y) >> (Long.SIZE - 1));
34+
return signum < 0 ? quotient + signum : quotient;
1635
}
1736

18-
private static boolean hasDifferentSigns(final long x, final long y) {
19-
return x < 0 != y < 0;
37+
static long floorMod(final long x, final long y) {
38+
return x - floorDiv(x, y) * y;
2039
}
2140
}

0 commit comments

Comments
 (0)