Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
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
9 changes: 9 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ public enum Feature {
* @since 2.5
*/
IGNORE_UNKNOWN(false),

/**
* Feature that determines whether to use standard Java code to write floats/doubles (default) or
* use the Schubfach algorithm which is faster. The latter approach may lead to small
* differences in the precision of the float/double that is written to the JSON output.
*
* @since 2.14
*/
USE_FAST_DOUBLE_WRITER(false)
;

private final boolean _defaultState;
Expand Down
41 changes: 36 additions & 5 deletions src/main/java/com/fasterxml/jackson/core/io/NumberOutput.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.fasterxml.jackson.core.io;

import com.fasterxml.jackson.core.io.schubfach.DoubleToDecimal;
import com.fasterxml.jackson.core.io.schubfach.FloatToDecimal;

public final class NumberOutput
{
private static int MILLION = 1000000;
Expand Down Expand Up @@ -273,13 +276,41 @@ public static String toString(long v) {
return Long.toString(v);
}

public static String toString(double v) {
return Double.toString(v);
/**
* @param v double
* @return double as a string
*/
public static String toString(final double v) {
return toString(v, false);
}

/**
* @param v double
* @param useFastWriter whether to use Schubfach algorithm to write output (default false)
* @return double as a string
* @since 2.14
*/
public static String toString(final double v, final boolean useFastWriter) {
return useFastWriter ? DoubleToDecimal.toString(v) : Double.toString(v);
}

// @since 2.6
public static String toString(float v) {
return Float.toString(v);
/**
* @param v float
* @return float as a string
* @since 2.6
*/
public static String toString(final float v) {
return toString(v, false);
}

/**
* @param v float
* @param useFastWriter whether to use Schubfach algorithm to write output (default false)
* @return float as a string
* @since 2.14
*/
public static String toString(final float v, final boolean useFastWriter) {
return useFastWriter ? FloatToDecimal.toString(v) : Float.toString(v);
}

/*
Expand Down
Loading