OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <stddef.h> // For offsetof(). | 7 #include <stddef.h> // For offsetof(). |
8 | 8 |
9 #include "../../include/fxcrt/fx_basic.h" | 9 #include "../../include/fxcrt/fx_basic.h" |
10 #include "../../../third_party/base/numerics/safe_math.h" | 10 #include "../../../third_party/base/numerics/safe_math.h" |
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 } | 1078 } |
1079 return strid; | 1079 return strid; |
1080 } | 1080 } |
1081 FX_STRSIZE FX_ftoa(FX_FLOAT d, FX_CHAR* buf) | 1081 FX_STRSIZE FX_ftoa(FX_FLOAT d, FX_CHAR* buf) |
1082 { | 1082 { |
1083 buf[0] = '0'; | 1083 buf[0] = '0'; |
1084 buf[1] = '\0'; | 1084 buf[1] = '\0'; |
1085 if (d == 0.0f) { | 1085 if (d == 0.0f) { |
1086 return 1; | 1086 return 1; |
1087 } | 1087 } |
1088 FX_BOOL bNegative = FALSE; | 1088 bool bNegative = false; |
1089 if (d < 0) { | 1089 if (d < 0) { |
1090 bNegative = TRUE; | 1090 bNegative = true; |
1091 d = -d; | 1091 d = -d; |
1092 } | 1092 } |
1093 int scale = 1; | 1093 int scale = 1; |
1094 int scaled = FXSYS_round(d); | 1094 int scaled = FXSYS_round(d); |
1095 while (scaled < 100000) { | 1095 while (scaled < 100000) { |
1096 if (scale == 1000000) { | 1096 if (scale == 1000000) { |
1097 break; | 1097 break; |
1098 } | 1098 } |
1099 scale *= 10; | 1099 scale *= 10; |
1100 scaled = FXSYS_round(d * scale); | 1100 scaled = FXSYS_round(d * scale); |
(...skipping 23 matching lines...) Expand all Loading... |
1124 scale /= 10; | 1124 scale /= 10; |
1125 } | 1125 } |
1126 return buf_size; | 1126 return buf_size; |
1127 } | 1127 } |
1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) | 1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) |
1129 { | 1129 { |
1130 FX_CHAR buf[32]; | 1130 FX_CHAR buf[32]; |
1131 FX_STRSIZE len = FX_ftoa(d, buf); | 1131 FX_STRSIZE len = FX_ftoa(d, buf); |
1132 return CFX_ByteString(buf, len); | 1132 return CFX_ByteString(buf, len); |
1133 } | 1133 } |
OLD | NEW |