Table of Contents

Class NDDivision

Namespace
NumSharp.Utilities
Assembly
NumSharp.dll

floor-division and remainder helpers matching NumPy's floor_div_@TYPE@ (loops_arithmetic.dispatch.c.src), integer remainder (loops_modulo.dispatch.c.src), and the floating-point npy_floor_divide@c@ / npy_remainder@c@ (Python-divmod port in npy_math_internal.h.src).

Semantics replicated exactly:

  • Integer divide/modulo by zero returns 0 (NumPy raises a RuntimeWarning but yields 0, never throwing — C#'s DivideByZeroException must not surface).
  • Signed integer floor-division rounds toward negative infinity (Python //), not toward zero like C# /; MIN // -1 wraps to MIN (overflow), matching NumPy's npy_set_floatstatus_overflow(); return NPY_MIN.
  • Signed integer remainder uses the floored (Python) sign convention: the result has the sign of the divisor; MIN % -1 == 0.
  • Float floor-division/modulo follow CPython's divmod (fmod, sign-fixup, snap-to-nearest-integer), so a // 0.0 is ±inf/nan (not forced NaN) and edge cases like 0.7 // 0.1 == 6.0 and -2.0 // inf == -1.0 match.
public static class NDDivision
Inheritance
NDDivision
Inherited Members

Methods

DivmodByte(byte, byte, out byte)

public static byte DivmodByte(byte n, byte d, out byte mod)

Parameters

n byte
d byte
mod byte

Returns

byte

DivmodChar(char, char, out char)

public static char DivmodChar(char n, char d, out char mod)

Parameters

n char
d char
mod char

Returns

char

DivmodDecimal(decimal, decimal, out decimal)

public static decimal DivmodDecimal(decimal a, decimal b, out decimal mod)

Parameters

a decimal
b decimal
mod decimal

Returns

decimal

DivmodDouble(double, double, out double)

Fused floating divmod (CPython npy_divmod port): returns the floored quotient and writes the floored remainder to modulus in ONE pass — the shared core behind FloorDivDouble(double, double) / RemDouble(double, double) and np.divmod's fused kernel. b == 0 yields (a/b, a%b) = (±inf/nan, nan), never a forced NaN.

public static double DivmodDouble(double a, double b, out double modulus)

Parameters

a double
b double
modulus double

Returns

double

DivmodHalf(Half, Half, out Half)

public static Half DivmodHalf(Half a, Half b, out Half mod)

Parameters

a Half
b Half
mod Half

Returns

Half

DivmodInt16(short, short, out short)

public static short DivmodInt16(short n, short d, out short mod)

Parameters

n short
d short
mod short

Returns

short

DivmodInt32(int, int, out int)

public static int DivmodInt32(int n, int d, out int mod)

Parameters

n int
d int
mod int

Returns

int

DivmodInt64(long, long, out long)

public static long DivmodInt64(long n, long d, out long mod)

Parameters

n long
d long
mod long

Returns

long

DivmodSByte(sbyte, sbyte, out sbyte)

public static sbyte DivmodSByte(sbyte n, sbyte d, out sbyte mod)

Parameters

n sbyte
d sbyte
mod sbyte

Returns

sbyte

DivmodSingle(float, float, out float)

Fused single-precision divmod — float32 twin of DivmodDouble(double, double, out double). Returns the floored quotient and writes the floored remainder; the shared core behind FloorDivSingle(float, float) / RemSingle(float, float) and float32 np.divmod.

public static float DivmodSingle(float a, float b, out float modulus)

Parameters

a float
b float
modulus float

Returns

float

DivmodUInt16(ushort, ushort, out ushort)

public static ushort DivmodUInt16(ushort n, ushort d, out ushort mod)

Parameters

n ushort
d ushort
mod ushort

Returns

ushort

DivmodUInt32(uint, uint, out uint)

public static uint DivmodUInt32(uint n, uint d, out uint mod)

Parameters

n uint
d uint
mod uint

Returns

uint

DivmodUInt64(ulong, ulong, out ulong)

public static ulong DivmodUInt64(ulong n, ulong d, out ulong mod)

Parameters

n ulong
d ulong
mod ulong

Returns

ulong

FloorDivByte(byte, byte)

public static byte FloorDivByte(byte n, byte d)

Parameters

n byte
d byte

Returns

byte

FloorDivChar(char, char)

public static char FloorDivChar(char n, char d)

Parameters

n char
d char

Returns

char

FloorDivDouble(double, double)

public static double FloorDivDouble(double a, double b)

Parameters

a double
b double

Returns

double

FloorDivInt16(short, short)

public static short FloorDivInt16(short n, short d)

Parameters

n short
d short

Returns

short

FloorDivInt32(int, int)

public static int FloorDivInt32(int n, int d)

Parameters

n int
d int

Returns

int

FloorDivInt64(long, long)

public static long FloorDivInt64(long n, long d)

Parameters

n long
d long

Returns

long

FloorDivSByte(sbyte, sbyte)

public static sbyte FloorDivSByte(sbyte n, sbyte d)

Parameters

n sbyte
d sbyte

Returns

sbyte

FloorDivSingle(float, float)

public static float FloorDivSingle(float a, float b)

Parameters

a float
b float

Returns

float

FloorDivUInt16(ushort, ushort)

public static ushort FloorDivUInt16(ushort n, ushort d)

Parameters

n ushort
d ushort

Returns

ushort

FloorDivUInt32(uint, uint)

public static uint FloorDivUInt32(uint n, uint d)

Parameters

n uint
d uint

Returns

uint

FloorDivUInt64(ulong, ulong)

public static ulong FloorDivUInt64(ulong n, ulong d)

Parameters

n ulong
d ulong

Returns

ulong

FmodByte(byte, byte)

public static byte FmodByte(byte n, byte d)

Parameters

n byte
d byte

Returns

byte

FmodChar(char, char)

public static char FmodChar(char n, char d)

Parameters

n char
d char

Returns

char

FmodDecimal(decimal, decimal)

public static decimal FmodDecimal(decimal a, decimal b)

Parameters

a decimal
b decimal

Returns

decimal

FmodDouble(double, double)

public static double FmodDouble(double a, double b)

Parameters

a double
b double

Returns

double

FmodInt16(short, short)

public static short FmodInt16(short n, short d)

Parameters

n short
d short

Returns

short

FmodInt32(int, int)

public static int FmodInt32(int n, int d)

Parameters

n int
d int

Returns

int

FmodInt64(long, long)

public static long FmodInt64(long n, long d)

Parameters

n long
d long

Returns

long

FmodSByte(sbyte, sbyte)

public static sbyte FmodSByte(sbyte n, sbyte d)

Parameters

n sbyte
d sbyte

Returns

sbyte

FmodSingle(float, float)

public static float FmodSingle(float a, float b)

Parameters

a float
b float

Returns

float

FmodUInt16(ushort, ushort)

public static ushort FmodUInt16(ushort n, ushort d)

Parameters

n ushort
d ushort

Returns

ushort

FmodUInt32(uint, uint)

public static uint FmodUInt32(uint n, uint d)

Parameters

n uint
d uint

Returns

uint

FmodUInt64(ulong, ulong)

public static ulong FmodUInt64(ulong n, ulong d)

Parameters

n ulong
d ulong

Returns

ulong

RemByte(byte, byte)

public static byte RemByte(byte n, byte d)

Parameters

n byte
d byte

Returns

byte

RemChar(char, char)

public static char RemChar(char n, char d)

Parameters

n char
d char

Returns

char

RemDouble(double, double)

public static double RemDouble(double a, double b)

Parameters

a double
b double

Returns

double

RemInt16(short, short)

public static short RemInt16(short n, short d)

Parameters

n short
d short

Returns

short

RemInt32(int, int)

public static int RemInt32(int n, int d)

Parameters

n int
d int

Returns

int

RemInt64(long, long)

public static long RemInt64(long n, long d)

Parameters

n long
d long

Returns

long

RemSByte(sbyte, sbyte)

public static sbyte RemSByte(sbyte n, sbyte d)

Parameters

n sbyte
d sbyte

Returns

sbyte

RemSingle(float, float)

public static float RemSingle(float a, float b)

Parameters

a float
b float

Returns

float

RemUInt16(ushort, ushort)

public static ushort RemUInt16(ushort n, ushort d)

Parameters

n ushort
d ushort

Returns

ushort

RemUInt32(uint, uint)

public static uint RemUInt32(uint n, uint d)

Parameters

n uint
d uint

Returns

uint

RemUInt64(ulong, ulong)

public static ulong RemUInt64(ulong n, ulong d)

Parameters

n ulong
d ulong

Returns

ulong