summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-06-15 14:19:29 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-06-15 14:19:29 +0800
commit94015a6835ae0d050a83dee1622e1d1b6851f556 (patch)
tree1adef6b6fc269123868a24da0e9a1bdf46ae1827 /src
parent194543a45e5a456a78746912e3dc561f096579f5 (diff)
downloadmrust-94015a6835ae0d050a83dee1622e1d1b6851f556.tar.gz
Codegen C - Fix float precision, disable test broken by fixed precision
Diffstat (limited to 'src')
-rw-r--r--src/trans/codegen_c.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index 68af508a..878a55d4 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -894,6 +894,18 @@ namespace {
m_mir_res = nullptr;
}
+ void emit_float(double v) {
+ if( ::std::isnan(v) ) {
+ m_of << "NAN";
+ }
+ else if( ::std::isinf(v) ) {
+ m_of << (v < 0 ? "-" : "") << "INFINITY";
+ }
+ else {
+ m_of.precision(::std::numeric_limits<double>::max_digits10 + 1);
+ m_of << ::std::scientific << v;
+ }
+ }
void emit_literal(const ::HIR::TypeRef& ty, const ::HIR::Literal& lit, const Trans_Params& params) {
TRACE_FUNCTION_F("ty=" << ty << ", lit=" << lit);
::HIR::TypeRef tmp;
@@ -1065,15 +1077,7 @@ namespace {
}
),
(Float,
- if( ::std::isnan(e) ) {
- m_of << "NAN";
- }
- else if( ::std::isinf(e) ) {
- m_of << "INFINITY";
- }
- else {
- m_of << e;
- }
+ this->emit_float(e);
),
(BorrowOf,
TU_MATCHA( (e.m_data), (pe),
@@ -2984,15 +2988,7 @@ namespace {
}
),
(Float,
- if( ::std::isnan(c.v) ) {
- m_of << "NAN";
- }
- else if( ::std::isinf(c.v) ) {
- m_of << (c.v < 0 ? "-" : "") << "INFINITY";
- }
- else {
- m_of << c.v;
- }
+ this->emit_float(c.v);
),
(Bool,
m_of << (c.v ? "true" : "false");