Skip to content

Instantly share code, notes, and snippets.

@overing
Created April 11, 2024 03:37
Show Gist options
  • Save overing/6fd46223e9e1ff151e08b69fc2090754 to your computer and use it in GitHub Desktop.
Save overing/6fd46223e9e1ff151e08b69fc2090754 to your computer and use it in GitHub Desktop.
乘法溢位範圍列表
using System;
using 計算單位 = uint;
using 驗證單位 = ulong; // 需要比計算單位大
Console.WriteLine($"計算單位: {typeof(計算單位).Name} (Max: {計算單位.MaxValue}), 驗證單位: {typeof(驗證單位).Name}");
for (計算單位 乘數 = 2; 乘數 <= (計算單位.MaxValue / 2); 乘數 += (計算單位)Math.Pow(10, Math.Floor(Math.Log10(乘數))))
{
for (計算單位 被乘數 = 1; 被乘數 < 計算單位.MaxValue; 被乘數++)
{
var total = (計算單位)(被乘數 * 乘數);
var assert = 被乘數 * (驗證單位)乘數;
if (total == assert)
continue;
Console.WriteLine($"乘數: {乘數}, 被乘數: {被乘數}, 計算結果: {total}, 驗證結果: {assert}");
break;
}
}
Console.WriteLine("Done (press any key to exit)");
Console.ReadKey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment