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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 } | 1079 } |
1080 return strid; | 1080 return strid; |
1081 } | 1081 } |
1082 FX_STRSIZE FX_ftoa(FX_FLOAT d, FX_CHAR* buf) | 1082 FX_STRSIZE FX_ftoa(FX_FLOAT d, FX_CHAR* buf) |
1083 { | 1083 { |
1084 buf[0] = '0'; | 1084 buf[0] = '0'; |
1085 buf[1] = '\0'; | 1085 buf[1] = '\0'; |
1086 if (d == 0.0f) { | 1086 if (d == 0.0f) { |
1087 return 1; | 1087 return 1; |
1088 } | 1088 } |
1089 FX_BOOL bNegative = FALSE; | 1089 bool bNegative = false; |
1090 if (d < 0) { | 1090 if (d < 0) { |
1091 bNegative = TRUE; | 1091 bNegative = true; |
1092 d = -d; | 1092 d = -d; |
1093 } | 1093 } |
1094 int scale = 1; | 1094 int scale = 1; |
1095 int scaled = FXSYS_round(d); | 1095 int scaled = FXSYS_round(d); |
1096 while (scaled < 100000) { | 1096 while (scaled < 100000) { |
1097 if (scale == 1000000) { | 1097 if (scale == 1000000) { |
1098 break; | 1098 break; |
1099 } | 1099 } |
1100 scale *= 10; | 1100 scale *= 10; |
1101 scaled = FXSYS_round(d * scale); | 1101 scaled = FXSYS_round(d * scale); |
(...skipping 23 matching lines...) Expand all Loading... |
1125 scale /= 10; | 1125 scale /= 10; |
1126 } | 1126 } |
1127 return buf_size; | 1127 return buf_size; |
1128 } | 1128 } |
1129 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) | 1129 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) |
1130 { | 1130 { |
1131 FX_CHAR buf[32]; | 1131 FX_CHAR buf[32]; |
1132 FX_STRSIZE len = FX_ftoa(d, buf); | 1132 FX_STRSIZE len = FX_ftoa(d, buf); |
1133 return CFX_ByteString(buf, len); | 1133 return CFX_ByteString(buf, len); |
1134 } | 1134 } |
OLD | NEW |