Solved

Function MOD

Posted on 2004-09-26
4
246 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 23

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month6 days, 15 hours left to enroll

622 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