Jump to content
Sign in to follow this  

Math functions

Recommended Posts


Functions for calculating factorials and binomial coefficients (aka choose):

Func _MathFactorial($number)
    If Not IsNumber($number) Then
        Return 0
    Local $value = 1
    For $i = 1 To $number
        $value *= $i
    Return $value

Func _MathChoose($num1, $num2)      ;Important: $num1 choose $num2
    If Not IsNumber($num1) And Not IsNumber($num2) Then
        Return 0
    If $num2 < 0 Or $num2 > $num1 Then Return 0
    Local $num1_Factorial = _MathFactorial($num1)
    Local $num2_Factorial = _MathFactorial($num2)
    Local $diff_Factorial = _MathFactorial($num1 - $num2)
    Local $value = $num1_Factorial/($num2_Factorial*$diff_Factorial)
    Return $value   

Edit: Added restraints for _MathChoose

Edited by mikehunt114

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.