# Macro that finds the minimum of its five arguments.

Page 1 of 1

## 3 Replies - 389 Views - Last Post: 10 November 2012 - 02:16 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=299549&amp;s=ffad78bc808dea68db22ad163754149d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 GraphicSpike

• New D.I.C Head

Reputation: 0
• Posts: 6
• Joined: 27-October 12

# Macro that finds the minimum of its five arguments.

Posted 10 November 2012 - 07:46 AM

I've been trying to figure out the right way to write a macro for 5 arguments.
I know to find the min of 2 arguments you use:

#define ( a , b ) / > a > b ? a : b

But to make 5 do I have to write it the same way I would write a function?

```  smallest = num1;
if (num2 < num1)
smallest = num2;
if (num3 < num2)
smallest = num3;
if (num4 < num3)
smallest = num4;
if (num5 < num4)
smallest = num5;

```

Or do you write it something like this:

```#define MIN5(1,2,3,4,5) (MIN2 (1 , MIN2 (2 , MIN2 ( 3 , MIN2 ( 4 , 5 ) ) ) ) )
```

Any help is greatly appreciated!

This post has been edited by jimblumberg: 10 November 2012 - 08:50 AM
Reason for edit:: Added missing Code Tags, Please learn to use them.

Is This A Good Question/Topic? 0

## Replies To: Macro that finds the minimum of its five arguments.

### #2 jimblumberg

Reputation: 4735
• Posts: 14,762
• Joined: 25-December 09

## Re: Macro that finds the minimum of its five arguments.

Posted 10 November 2012 - 08:27 AM

I myself would use an array and a loop.

Jim

### #3 #define

• Duke of Err

Reputation: 1633
• Posts: 5,752
• Joined: 19-February 09

## Re: Macro that finds the minimum of its five arguments.

Posted 10 November 2012 - 10:19 AM

I would say breaking it down in to separate macros would be easiest, if you're allowed.

So you would need MIN5, MIN4 and MIN2.

You could do it with one macro using MIN2, try creating MIN4 or MIN3 first to give you an idea.

• D.I.C Lover

Reputation: 331
• Posts: 1,168
• Joined: 01-April 11

## Re: Macro that finds the minimum of its five arguments.

Posted 10 November 2012 - 02:16 PM

I appreciate the intellectual exercise involved, but you know, you're heading hard and fast, straight for MACRO HELL, don't you?

Just checking < smile >

This post has been edited by Adak: 10 November 2012 - 02:17 PM