• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Smallest integer multiple of a number >= another number

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,337
Hi,

Here is an example:

a = 4

b = 7

foo(4, 7) = 2, because 2 is the smallest multiple of 4 which is greater than or equal to 7 (2 * 4 = 8 >= 7)

Another example:

a = 2

b = 5

foo(2, 5) = 3, because 3 is the smallest multiple of 2 which is greater than or equal to 5 (3 * 2 = 6 >= 5)

How to get this function in JASS?
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
JASS:
function foo takes integer a, integer b returns integer
    /* 
    error check if you want
    if a <= 0 or b <= 0 then
        return 0
    elseif a > b then
        return foo(b, a)
    endif
    */

    if (b/a * a == b) then
        return b/a
    else
        return b/a + 1
    endif
endfunction
 
Level 15
Joined
Aug 7, 2013
Messages
1,337
I doubt a, b will ever be higher than 100 (I don't see them even reaching ~20). So it shouldn't be an issue, but thank you for pointing this out as a note when using muzzel's solution.
 
Status
Not open for further replies.
Top