@@ -193,6 +193,8 @@ public abstract class ParserBase extends ParserMinimalBase
193
193
194
194
protected long _numberLong ;
195
195
196
+ protected float _numberFloat ;
197
+
196
198
protected double _numberDouble ;
197
199
198
200
// And then object types
@@ -615,6 +617,9 @@ public Number getNumberValue() throws IOException
615
617
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
616
618
return _numberBigDecimal ;
617
619
}
620
+ if ((_numTypesValid & NR_FLOAT ) != 0 ) {
621
+ return _numberFloat ;
622
+ }
618
623
if ((_numTypesValid & NR_DOUBLE ) == 0 ) { // sanity check
619
624
_throwInternal ();
620
625
}
@@ -647,6 +652,9 @@ public Number getNumberValueExact() throws IOException
647
652
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
648
653
return _numberBigDecimal ;
649
654
}
655
+ if ((_numTypesValid & NR_FLOAT ) != 0 ) {
656
+ return _numberFloat ;
657
+ }
650
658
if ((_numTypesValid & NR_DOUBLE ) == 0 ) { // sanity check
651
659
_throwInternal ();
652
660
}
@@ -678,6 +686,9 @@ public NumberType getNumberType() throws IOException
678
686
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
679
687
return NumberType .BIG_DECIMAL ;
680
688
}
689
+ if ((_numTypesValid & NR_FLOAT ) != 0 ) {
690
+ return NumberType .FLOAT ;
691
+ }
681
692
return NumberType .DOUBLE ;
682
693
}
683
694
@@ -726,7 +737,6 @@ public BigInteger getBigIntegerValue() throws IOException
726
737
@ Override
727
738
public float getFloatValue () throws IOException
728
739
{
729
- double value = getDoubleValue ();
730
740
/* 22-Jan-2009, tatu: Bounds/range checks would be tricky
731
741
* here, so let's not bother even trying...
732
742
*/
@@ -735,7 +745,15 @@ public float getFloatValue() throws IOException
735
745
_reportError("Numeric value ("+getText()+") out of range of Java float");
736
746
}
737
747
*/
738
- return (float ) value ;
748
+ if ((_numTypesValid & NR_FLOAT ) == 0 ) {
749
+ if (_numTypesValid == NR_UNKNOWN ) {
750
+ _parseNumericValue (NR_FLOAT );
751
+ }
752
+ if ((_numTypesValid & NR_FLOAT ) == 0 ) {
753
+ convertNumberToFloat ();
754
+ }
755
+ }
756
+ return _numberFloat ;
739
757
}
740
758
741
759
@ Override
@@ -874,6 +892,9 @@ private void _parseSlowFloat(int expType) throws IOException
874
892
if (expType == NR_BIGDECIMAL ) {
875
893
_numberBigDecimal = _textBuffer .contentsAsDecimal ();
876
894
_numTypesValid = NR_BIGDECIMAL ;
895
+ } else if (expType == NR_FLOAT ) {
896
+ _numberFloat = _textBuffer .contentsAsFloat ();
897
+ _numTypesValid = NR_FLOAT ;
877
898
} else {
878
899
// Otherwise double has to do
879
900
_numberDouble = _textBuffer .contentsAsDouble ();
@@ -1031,11 +1052,37 @@ protected void convertNumberToDouble() throws IOException
1031
1052
_numberDouble = (double ) _numberLong ;
1032
1053
} else if ((_numTypesValid & NR_INT ) != 0 ) {
1033
1054
_numberDouble = (double ) _numberInt ;
1055
+ } else if ((_numTypesValid & NR_FLOAT ) != 0 ) {
1056
+ _numberDouble = (double ) _numberFloat ;
1034
1057
} else {
1035
1058
_throwInternal ();
1036
1059
}
1037
1060
_numTypesValid |= NR_DOUBLE ;
1038
1061
}
1062
+
1063
+ protected void convertNumberToFloat () throws IOException
1064
+ {
1065
+ /* 05-Aug-2008, tatus: Important note: this MUST start with
1066
+ * more accurate representations, since we don't know which
1067
+ * value is the original one (others get generated when
1068
+ * requested)
1069
+ */
1070
+
1071
+ if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1072
+ _numberFloat = _numberBigDecimal .floatValue ();
1073
+ } else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1074
+ _numberFloat = _numberBigInt .floatValue ();
1075
+ } else if ((_numTypesValid & NR_LONG ) != 0 ) {
1076
+ _numberFloat = (float ) _numberLong ;
1077
+ } else if ((_numTypesValid & NR_INT ) != 0 ) {
1078
+ _numberFloat = (float ) _numberInt ;
1079
+ } else if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1080
+ _numberFloat = (float ) _numberDouble ;
1081
+ } else {
1082
+ _throwInternal ();
1083
+ }
1084
+ _numTypesValid |= NR_FLOAT ;
1085
+ }
1039
1086
1040
1087
protected void convertNumberToBigDecimal () throws IOException
1041
1088
{
0 commit comments