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

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

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