Skip to content

fix checking a surrogate pair #232

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/main/java/com/jsoniter/IterImpl.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.jsoniter;

import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

import com.jsoniter.any.Any;
import com.jsoniter.spi.JsonException;
import com.jsoniter.spi.Slice;

import java.io.IOException;
import java.math.BigInteger;

class IterImpl {

private static BigInteger maxLong = BigInteger.valueOf(Long.MAX_VALUE);
Expand Down Expand Up @@ -469,7 +470,10 @@ static final double readDouble(final JsonIterator iter) throws IOException {
decimalPart = -decimalPart;
int decimalPlaces = iter.head - start;
if (decimalPlaces > 0 && decimalPlaces < IterImplNumber.POW10.length && (iter.head - oldHead) < 10) {
return value + (decimalPart / (double) IterImplNumber.POW10[decimalPlaces]);
BigDecimal integerPart = new BigDecimal(value);
BigDecimal fractionalPart = new BigDecimal((decimalPart / (double) IterImplNumber.POW10[decimalPlaces]));
BigDecimal result = integerPart.add(fractionalPart).setScale(decimalPlaces,BigDecimal.ROUND_HALF_UP);
return result.doubleValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t-mangoe do you have tests and benchmarks that prove need for this change?

also I would move this commit to the separated pull request

Copy link
Author

@t-mangoe t-mangoe Apr 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plokhotnyuk Sorry. This commit targets another issue. I will revert this commit, and make separeted pull request. Thanks.

} else {
iter.head = oldHead;
return IterImplForStreaming.readDoubleSlowPath(iter);
Expand Down