Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Function MOD

Posted on 2004-09-26
4
Medium Priority
?
247 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 200 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 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

by:AgeOfWars
ID: 12156622
Thanks guys,

it works :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

722 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