Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Function MOD

Posted on 2004-09-26
Medium Priority
250 Views
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
Question by:AgeOfWars

LVL 23

Accepted Solution

Ferruccio Accalai earned 200 total points
ID: 12155948
you can use

uses Math

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

LVL 31

Expert Comment

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

Delphian earned 80 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

ID: 12156622
Thanks guys,

it works :)
0

## Featured Post

Question has a verified solution.

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

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
###### Suggested Courses
Course of the Month12 days, 14 hours left to enroll