diff --git a/katas/content/complex_arithmetic/Common.qs b/katas/content/complex_arithmetic/Common.qs index f7dc8ae3d4..4dd4d1c02f 100644 --- a/katas/content/complex_arithmetic/Common.qs +++ b/katas/content/complex_arithmetic/Common.qs @@ -11,15 +11,17 @@ namespace Kata.Verification { } function ComplexAsString(x : Complex) : String { + let precision = 3; if x.Imag < 0.0 { - $"{x.Real} - {AbsD(x.Imag)}i" + $"{DoubleAsStringWithPrecision(x.Real, precision)} - {DoubleAsStringWithPrecision(AbsD(x.Imag), precision)}i" } else { - $"{x.Real} + {x.Imag}i" + $"{DoubleAsStringWithPrecision(x.Real, precision)} + {DoubleAsStringWithPrecision(x.Imag, precision)}i" } } function ComplexPolarAsString(x : ComplexPolar) : String { - $"{x.Magnitude} * exp({x.Argument}i)" + let precision = 3; + $"{DoubleAsStringWithPrecision(x.Magnitude, precision)} * exp({DoubleAsStringWithPrecision(x.Argument, precision)}i)" } operation CheckTwoComplexOpsAreSame(sol : (Complex, Complex) -> Complex, ref : (Complex, Complex) -> Complex) : Bool { diff --git a/katas/content/complex_arithmetic/complex_modulus/Verification.qs b/katas/content/complex_arithmetic/complex_modulus/Verification.qs index f29ba78cf4..ef18bae52c 100644 --- a/katas/content/complex_arithmetic/complex_modulus/Verification.qs +++ b/katas/content/complex_arithmetic/complex_modulus/Verification.qs @@ -1,4 +1,5 @@ namespace Kata.Verification { + open Microsoft.Quantum.Convert; open Microsoft.Quantum.Math; @EntryPoint() @@ -10,8 +11,9 @@ namespace Kata.Verification { let actual = Kata.ComplexModulus(x); if AbsD(expected - actual) > 1e-6 { + let precision = 3; Message("Incorrect"); - Message($"For x = {ComplexAsString(x)} expected return {expected}, actual return {actual}."); + Message($"For x = {ComplexAsString(x)} expected return {DoubleAsStringWithPrecision(expected, precision)}, actual return {DoubleAsStringWithPrecision(actual, precision)}."); return false; } } diff --git a/katas/content/complex_arithmetic/complex_powers_real/Verification.qs b/katas/content/complex_arithmetic/complex_powers_real/Verification.qs index 94d0e801cb..93000e00a2 100644 --- a/katas/content/complex_arithmetic/complex_powers_real/Verification.qs +++ b/katas/content/complex_arithmetic/complex_powers_real/Verification.qs @@ -1,4 +1,5 @@ namespace Kata.Verification { + open Microsoft.Quantum.Convert; open Microsoft.Quantum.Math; open Microsoft.Quantum.Random; @@ -21,8 +22,9 @@ namespace Kata.Verification { let actual = Kata.ComplexExpReal(r, x); if not ComplexEqual(expected, actual) { + let precision = 3; Message("Incorrect"); - Message($"For x = {ComplexAsString(x)} and r = {r} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}."); + Message($"For x = {ComplexAsString(x)} and r = {DoubleAsStringWithPrecision(r, precision)} expected return {ComplexAsString(expected)}, actual return {ComplexAsString(actual)}."); return false; } }