Livt packages

Livt.Math

Version 1.7.2

Reusable integer and fixed-point arithmetic, complex numbers, trigonometry, and statistics for FPGA applications written in Livt.

Published files (90)

src/arithmetic/UnsignedDivideInt32.lvt

namespace Livt.Math.Arithmetic

/**
 * Compatibility adapter for nonnegative signed-int32 floor division.
 * New consumers can use UnsignedDivision for quotient, remainder, and explicit status.
 * Invalid negative inputs or a zero divisor retain the historical zero result.
 */
component UnsignedDivideInt32
{
	// Number of magnitude bits accepted by the historical API.
	public const ITERATIONS: int = 31

	// Shared implementation of exact scheduled division.
	divider: UnsignedDivision<31>

	/**
	 * Owns one worker; calls must be serialized.
	 */
	new()
	{
		divider = new UnsignedDivision<31>()
	}

	/**
	 * Returns the floor quotient, or zero for invalid input.
	 */
	public fn Compute(dividend: int, divisor: int) int
	{
		if (dividend < 0 || divisor <= 0) {
			return 0
		}

		return divider.Divide(dividend as uint, divisor as uint) as int
	}
}