Browse Source

Modifying how things print out to aid in debugging

tristangurtler 3 years ago
parent
commit
b7b1339376
3 changed files with 51 additions and 9 deletions
  1. 2 0
      bgn2/inc/print_helpers.hpp
  2. 12 2
      bgn2/src/Bipoint.cpp
  3. 37 7
      bgn2/src/print_helpers.cpp

+ 2 - 0
bgn2/inc/print_helpers.hpp

@@ -53,5 +53,7 @@ class Fpe {
 
 std::ostream& hex_double(std::ostream& os, double d);
 std::istream& hex_double(std::istream& is, double& d);
+std::ostream& raw_double(std::ostream& os, double d);
+std::istream& raw_double(std::istream& is, double& d);
 
 #endif

+ 12 - 2
bgn2/src/Bipoint.cpp

@@ -180,7 +180,12 @@ std::ostream& operator<<(std::ostream& os, const CurveBipoint& output)
 	affine_out.make_affine();
 
 	for (int i = 0; i < 2; i++)
-		os << Fpe(affine_out[i]->m_x) << Fpe(affine_out[i]->m_y) << Fpe(affine_out[i]->m_z);
+	{
+		if (fpe_iszero(affine_out[i]->m_z))
+			os << "Infinity";
+		else
+			os << Fpe(affine_out[i]->m_x) << Fpe(affine_out[i]->m_y) << Fpe(affine_out[i]->m_z);
+	}
 
 	return os;
 }
@@ -205,7 +210,12 @@ std::ostream& operator<<(std::ostream& os, const TwistBipoint& output)
 	affine_out.make_affine();
 
 	for (int i = 0; i < 2; i++)
-		os << Fp2e(output[i]->m_x) << Fp2e(output[i]->m_y) << Fp2e(output[i]->m_z);
+	{
+		if (fp2e_iszero(affine_out[i]->m_z))
+			os << "Infinity";
+		else
+			os << Fp2e(affine_out[i]->m_x) << Fp2e(affine_out[i]->m_y) << Fp2e(affine_out[i]->m_z);
+	}
 
 	return os;
 }

+ 37 - 7
bgn2/src/print_helpers.cpp

@@ -98,28 +98,58 @@ std::istream& operator>>(std::istream& is, Fp2e& input)
 
 std::ostream& operator<<(std::ostream& os, const Fpe& output)
 {
-    for (int i = 0; i < 12; i++)
-        hex_double(os, output.data->v[i]);
+    if (os.flags() | std::ios::hex)
+    {
+        for (int i = 0; i < 12; i++)
+            hex_double(os, output.data->v[i]);
+    }
+    else
+    {
+        for (int i = 0; i < 12; i++)
+            raw_double(os, output.data->v[i]);
+    }
 
     return os;
 }
 
 std::istream& operator>>(std::istream& is, Fpe& input)
-{ 
-    for (int i = 0; i < 12; i++)
-        hex_double(is, input.data->v[i]);
-
+{
+    if (is.flags() | std::ios::hex)
+    {
+        for (int i = 0; i < 12; i++)
+            hex_double(is, input.data->v[i]);
+    }
+    else
+    {
+        for (int i = 0; i < 12; i++)
+            raw_double(is, input.data->v[i]);
+    }
+    
     return is;       
 }
 
 std::ostream& hex_double(std::ostream& os, double d)
 {
-    os.write(reinterpret_cast<const char*>(&d), sizeof(d));
+    os << *reinterpret_cast<const unsigned long long*>(&d);
 
     return os;
 }
 
 std::istream& hex_double(std::istream& is, double& d)
+{ 
+    is >> *reinterpret_cast<unsigned long long*>(&d);
+
+    return is;
+}
+
+std::ostream& raw_double(std::ostream& os, double d)
+{
+    os.write(reinterpret_cast<const char*>(&d), sizeof(d));
+
+    return os;
+}
+
+std::istream& raw_double(std::istream& is, double& d)
 { 
     is.read(reinterpret_cast<char*>(&d), sizeof(d));