Commit b892fc66 by alokp@chromium.org

Make sure that floats are written with at least one decimal point.

Review URL: http://codereview.appspot.com/1144041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@243 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 194522f6
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
#include "compiler/Common.h" #include "compiler/Common.h"
// Returns the fractional part of the given floating-point number.
inline float fractionalPart(float f) {
return fmodf(f, 1.0f);
}
// //
// TPrefixType is used to centralize how info log messages start. // TPrefixType is used to centralize how info log messages start.
// See below. // See below.
...@@ -44,10 +49,16 @@ public: ...@@ -44,10 +49,16 @@ public:
TInfoSinkBase& operator<<(const char* s) { append(s); return *this; } TInfoSinkBase& operator<<(const char* s) { append(s); return *this; }
TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; } TInfoSinkBase& operator<<(int n) { append(String(n)); return *this; }
TInfoSinkBase& operator<<(const unsigned int n) { append(String(n)); return *this; } TInfoSinkBase& operator<<(const unsigned int n) { append(String(n)); return *this; }
TInfoSinkBase& operator<<(float n) { char buf[40]; TInfoSinkBase& operator<<(float n) {
sprintf(buf, "%.8g", n); char buf[40];
append(buf); // Make sure that at least one decimal point is written. If a number
return *this; } // does not have a fractional part, %g does not written the decimal
// portion which gets interpreted as integer by the compiler.
const char* format = fractionalPart(n) == 0.0f ? "%.1f" : "%.8g";
sprintf(buf, format, n);
append(buf);
return *this;
}
TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; } TInfoSinkBase& operator+(const TPersistString& t) { append(t); return *this; }
TInfoSinkBase& operator+(const TString& t) { append(t); return *this; } TInfoSinkBase& operator+(const TString& t) { append(t); return *this; }
TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; } TInfoSinkBase& operator<<(const TString& t) { append(t); return *this; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment