Solved

Function MOD

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now