Solved

Function MOD

Posted on 2004-09-26
4
245 Views
Last Modified: 2010-04-05
Hi experts,

I have 2 values: A and B. I'm using the function MOD.

if A > B then
 result := A mod B
if A < B then
 result := B mod A

I'm just wondering whether there is a shorter way to write this using the function MOD. I mean whether there is a way that the program will detect which value is bigger and do the function for you. Thank you.
Ian
0
Comment
Question by:AgeOfWars
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 50 total points
ID: 12155948
you can use

uses Math

result := Max(A,B) mod Min(A,B);
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 12156052
You have to watch out for the special cases which should be tested for on input:-

A=B (not explicitly catered for in the asker's example)

A=0; B>A
B=0; A>B

in any solution that is chosen.  
0
 
LVL 4

Assisted Solution

by:Delphian
Delphian earned 20 total points
ID: 12156595
uses Math
A := IfThen(A <> 0, A, B)
B := IfThen(B <> 0, B, 1)
result := Max(A,B) mod Min(A,B);

Hope this helps.

[]s






0
 

Author Comment

by:AgeOfWars
ID: 12156622
Thanks guys,

it works :)
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question