Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
rzError
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { // Make rotation r -180 <= r <= 180 static double Normalize(double degrees) { while (degrees > 180) degrees -= 360; while (degrees < -180) degrees += 360; return degrees; } static void TestRzError(double target, double current, double expected) { double rzError = Normalize(((current%360) - (target%360)) % 360); const double tol = 1e-6; if (Math.Abs(rzError - expected) > tol) Console.WriteLine("{0} {1} error is {2} but expected {3}", target, current, rzError, expected); } public static void Main(string[] args) { TestRzError(180, 0, -180); // Expect -180 TestRzError(0, 180, 180); // Expect 180 TestRzError(90, 0, -90); // Expect -90 TestRzError(0, 90, 90); // Expect 90 TestRzError(180, -180, 0); // Expect 0 TestRzError(-180, 180, 0); // Expect 0 TestRzError(180, 0.01, -179.99); // Expect -179.99 TestRzError(0.01, 180, 179.99); // Expect 179.99 TestRzError(180, -179.99, .01); // Expect .01 TestRzError(180, 179.99, -.01); // Expect -.01 TestRzError(-180, -179.99, .01); // Expect .01 TestRzError(-180, 179.99, -.01); // Expect -.01 TestRzError(180.01, -179.99, 0); // Expect 0 TestRzError(-179.99, 180.01, 0); // Expect 0 TestRzError(179.99, -179.99, .02); // Expect 0.02 TestRzError(-179.99, 179.99, -.02); // Expect -0.02 TestRzError(180, 89.995, -90.005); // Expect -90.005 TestRzError(-5, -4, 1); // Expect 1 TestRzError(-4, -5, -1); // Expect -1 // Don't try this at home! TestRzError(180, -1800, -180); // Expect -180 TestRzError(-1800, 180, 180); // Expect 180 } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,12 sec, absolute running time: 0,09 sec, cpu time: 0,08 sec, average memory usage: 13 Mb, average nr of threads: 3
edit mode
|
history
|
discussion