Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
F64 Clamp(F64 d, F64 lo, F64 hi)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Clamp to F64 [] range.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (d < lo)
|
2020-02-20 23:40:10 +00:00
|
|
|
return lo;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (d > hi)
|
2020-02-20 23:40:10 +00:00
|
|
|
return hi;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
return d;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
F64 Min(F64 n1, F64 n2)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Min of two F64s.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (n1 <= n2)
|
2020-02-20 23:40:10 +00:00
|
|
|
return n1;
|
|
|
|
else
|
|
|
|
return n2;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
F64 Max(F64 n1, F64 n2)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Max of two F64s.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (n1 >= n2)
|
2020-02-20 23:40:10 +00:00
|
|
|
return n1;
|
|
|
|
else
|
|
|
|
return n2;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
F64 Pow10I64(I64 i)
|
|
|
|
{//F64 int powers of ten.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (i > 308)
|
2023-11-12 15:40:40 +00:00
|
|
|
return ∞;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
else if (i < -308)
|
2020-02-20 23:40:10 +00:00
|
|
|
return 0.0;
|
|
|
|
else
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
return pow10_I64[i + 309];
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U64 FloorU64(U64 num, U64 to)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Int multiples of num.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
return num - num % to;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
U64 CeilU64(U64 num, U64 to)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Int multiples of num.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
num += to - 1;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
return num - num % to;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
I64 RoundI64(I64 num, I64 to)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Int multiples of num.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
return num - num % to;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
I64 FloorI64(I64 num, I64 to)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Int multiples of num.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (num >= 0)
|
|
|
|
return num - num % to;
|
|
|
|
else
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
num++;
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
return num - num % to - to;
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
I64 CeilI64(I64 num, I64 to)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Int multiples of num.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (num >= 0)
|
|
|
|
{
|
|
|
|
num += to - 1;
|
|
|
|
return num - num % to;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
num += to - 1;
|
|
|
|
return num - num % to - to;
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//See $LK,"::/Doc/Credits.DD"$.
|
2020-02-20 23:40:10 +00:00
|
|
|
#define LIN_CONGRUE_A 6364136223846793005
|
|
|
|
#define LIN_CONGRUE_C 1442695040888963407
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-02-18 02:02:37 +00:00
|
|
|
I64 RandInt()
|
|
|
|
{//Don't use this. Use the functions below.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res = Fs->rand_seed;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
res = LIN_CONGRUE_A * res ^ (res & 0xFFFFFFFF0000) >> 16 + LIN_CONGRUE_C;
|
|
|
|
if (!Bt(&Fs->task_flags, TASKf_NONTIMER_RAND))
|
2020-03-19 20:59:53 +00:00
|
|
|
res ^= TSCGet;
|
2020-02-20 23:40:10 +00:00
|
|
|
Fs->rand_seed = res;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
return res;
|
2020-02-18 02:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U8 RandU8()
|
|
|
|
{//Random U8.
|
2020-02-20 23:40:10 +00:00
|
|
|
return RandInt & U8_MAX;
|
2020-02-18 02:02:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 20:01:48 +00:00
|
|
|
I16 RandI16()
|
|
|
|
{//Random I16.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res = RandInt;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
return res.i16[0];
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U16 RandU16()
|
|
|
|
{//Random U16.
|
2020-02-20 23:40:10 +00:00
|
|
|
return RandInt & U16_MAX;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
I32 RandI32()
|
|
|
|
{//Random I32.
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 res = RandInt;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
return res.i32[0];
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U32 RandU32()
|
|
|
|
{//Random U32.
|
2020-02-20 23:40:10 +00:00
|
|
|
return RandInt & U32_MAX;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
I64 RandI64()
|
|
|
|
{//Random I64.
|
2020-02-20 23:40:10 +00:00
|
|
|
return RandInt;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U64 RandU64()
|
|
|
|
{//Random U64.
|
2020-02-20 23:40:10 +00:00
|
|
|
return RandInt;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
F64 Rand()
|
|
|
|
{//Random F64.
|
2020-02-20 23:40:10 +00:00
|
|
|
return (RandInt & 0x3FFFFFFFFFFFFFFF) / ToF64(0x4000000000000000);
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
I64 Seed(I64 seed=0, CTask *task=NULL)
|
2020-02-15 20:01:48 +00:00
|
|
|
{//Set $LK,"Rand",A="MN:Rand"$() seed. Zero for timer-based.
|
Reformatted more Kernel files.
Reformatted KMathA.CC, KMathB.CC, KMisc.CC, KTask.CC, KUtils.CC, Kernel.PRJ, KernelA.HH, KernelB.HH, KernelC.HH, KeyDev.CC, MultiProc.CC, PCIBIOS.CC, QuickSort.CC, Sched.CC, StrA.CC, StrB.CC, StrPrint.CC, StrScan.CC.
All top-level Kernel files are now reformatted. Remaining are files in Kernel/ subdirectories.
2020-09-12 22:37:51 +01:00
|
|
|
if (!task)
|
|
|
|
task = Fs;
|
|
|
|
if (seed)
|
|
|
|
{
|
|
|
|
LBts(&task->task_flags, TASKf_NONTIMER_RAND);
|
|
|
|
return task->rand_seed = seed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LBtr(&task->task_flags, TASKf_NONTIMER_RAND);
|
|
|
|
return task->rand_seed ^= TSCGet;
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|