1. Home
  2. Computing & Technology
  3. Delphi Programming
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

DivMod

unit
Math
category
arithmetic routines

declaration
procedure DivMod(Dividend: Integer; Divisor: Word; var Result, Remainder: Word);

description
Returns the integer and the remainder of an integer division, in one operation.

DivMod is a handy procedure when you need a result from an integer division (Dividend / Divisor) along with the remainder. You can use mod and div arithemic operators to substitute the DivMod procedurem but in more than one step.
Result := Dividend div Divisor;
Remainder := Dividend mod Divisor;

The operation below explains the div and mod operators:
Dividend mod Divisor = Dividend - (Dividend div Divisor) * Divisor.

example
const
 Dividend = 7;
 Divisor = 3;
var
 Result, Remainder : word;

DivMod(Dividend, Divisor, Result, Remainder)	

//Result = 2
//Remainder = 1

in real code

see also


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.