Solved

Function MOD

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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