KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Recently I discovered that C#'s operator % is applicable to double. Tried some things out, and after all came up with this test: class Program { static void test(double a, double b) { if (a % b != a - b * Math.Truncate(a / b)) { Console.WriteLine(a + ", " + b); } } static void Main(string[] args) { test(2.5, 7); test(-6.7, -3); test(8.7, 4); //... } } Everything in this test works. Is a % b always equivalent to a - b*Math.Round(a/b) ? If not, please explain to me how this operator really works. EDIT: Answering to James L, I understand that this is a modulo operator and everything. I'm curious only about how it works with double , integers I understand.
Tags (comma-separated)
Save Edits
Cancel