-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Use Double.NEGATIVE_INFINITY and Double.POSITIVE_INFINITY #4496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3ea542f
963b245
53b4d27
9719b56
db0cfc2
fd8e343
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.jackson; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class JacksonExtremeDoubleValuesSerdeTest | ||
| { | ||
| @Test | ||
| public void testExtremeDoubleValuesSerde() throws IOException | ||
| { | ||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| for (double value : new double[] {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}) { | ||
| String serialized = objectMapper.writeValueAsString(value); | ||
| Assert.assertEquals(new Double(value), objectMapper.readValue(serialized, Double.class)); | ||
| } | ||
| String negativeInfinityString = objectMapper.writeValueAsString(Double.NaN); | ||
| Assert.assertTrue(objectMapper.readValue(negativeInfinityString, Double.class).isNaN()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,10 +71,31 @@ | |
| <property name="illegalPattern" value="true"/> | ||
| <property name="message" value="Use Comparators.naturalNullsFirst() instead of Ordering.natural().nullsFirst()"/> | ||
| </module> | ||
|
|
||
| <module name="Regexp"> | ||
| <property name="format" value="(Byte|Character|Short|Integer|Long|Float|Double)\.TYPE"/> | ||
| <property name="illegalPattern" value="true"/> | ||
| <property name="message" value="Use primitive.class instead. But check twice that you don't actually need BoxedPrimitive.class instead of BoxedPrimitive.TYPE"/> | ||
| </module> | ||
| <module name="Regexp"> | ||
| <property name="format" value="Float\.MAX_VALUE"/> | ||
| <property name="illegalPattern" value="true"/> | ||
| <property name="message" value="Use Float.POSITIVE_INFINITY"/> | ||
| </module> | ||
| <module name="Regexp"> | ||
| <property name="format" value="Float\.MIN_VALUE"/> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure how this check style will work. Does this means any usage of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes; see #4496 (comment). I guess if anyone needs it for real then the checkstyle rule could be removed or altered. |
||
| <property name="illegalPattern" value="true"/> | ||
| <property name="message" value="Use Float.NEGATIVE_INFINITY"/> | ||
| </module> | ||
| <module name="Regexp"> | ||
| <property name="format" value="Double\.MAX_VALUE"/> | ||
| <property name="illegalPattern" value="true"/> | ||
| <property name="message" value="Use Double.POSITIVE_INFINITY"/> | ||
| </module> | ||
| <module name="Regexp"> | ||
| <property name="format" value="Double\.MIN_VALUE"/> | ||
| <property name="illegalPattern" value="true"/> | ||
| <property name="message" value="Use Double.NEGATIVE_INFINITY"/> | ||
| </module> | ||
| </module> | ||
| </module> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,7 @@ public static double applyCorrection(double e, int zeroCount) | |
| final double ratio = e / TWO_TO_THE_SIXTY_FOUR; | ||
| if (ratio >= 1) { | ||
| // handle very unlikely case that value is > 2^64 | ||
| return Double.MAX_VALUE; | ||
| return Double.POSITIVE_INFINITY; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment above why this need to be +infinity and not just Max_value ? |
||
| } else { | ||
| return -TWO_TO_THE_SIXTY_FOUR * Math.log(1 - ratio); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with the code of Rtree but am not sure if this change really make sense. After this change any operation on the root node coordinate will always return infinity, while before i can have for instance an incremental change over the root coordinate.
Eg,
node.getMinCoordinates()[0] [* or /] 100will returnInfinityif we useFloat.NEGATIVE_INFINITYas oppose to it will have a defined value if we keepFloat.MAX_VALUEThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be ok. I didn't check the full code around RTree in druid, but usually the min/max coordinates of an RTree node represents a minimum range covering all coordinates of the children nodes. It is used for early pruning when traversing the tree. So, I think the min/max coordinates of the root node shouldn't used for any computation.