Jump to content

New Math functions


trancexx
 Share

Recommended Posts

Return Values

If you look at the include file Math.au3 , you can see what return values are being used at a glance.

An example,

#include <Math.au3>
$a = "-4"
$b = "0"
MsgBox(0, "","The lower of the two numbers, " & $a & " and " & $b & " is " & _Min($a, $B))oÝ÷ Ù8b±û§rب+^®ØZØZ¶)Üç^v)ÌjØZ»w.®·§¶jvÞj[^­çm¢jøtSÀLZºÚ"µÍY   ÌÍÛHH[   ÌÍÛH[]Ù]Ü

As I said before speed is crucial here and that's why now I have doubts about using msvcrt.dll -too much time is lost with DllCall().

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I disagree. You should let your personal preferences be heard and the argumentation behind them, so that you may inspire others and let them see this problem from another perspective and possibly come up with other and better solutions. For the sake of open discussion.

Constantly trying to force your opinions onto others is another matter all together and should never be allowed.

I disagree with your disagreement.

Just because we all have ideas doesn't mean that they all warrant consideration - some people are just plain wrong.

If AutoIt was still open-source then there might be some argument in 'open discussion' of how the language should progress. It isn't, and thus there should be a standard set by those who understand the future of AI (Jon + the devs). Quoting Jon in 2001: "if someone asked for a function I stuck it in there. The problems this caused is why we don't give in all the time any more". Pandering to everyone's ideas results in a hideous mess. Standardisation (ISO, CE, IST, CPA etc etc) is important and ubiquitous.

I still think we could do with some sort of 'official' guidance on how to return failed math functions....and in my opinion returning zero is confounding. BUT if Jon (or the devs) were to say "we think the best option is to return zero", then so be it - that's what we should do.

Anyway, this is getting ot, so I won't argue it any more...I think I've made my point.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

I did some research on this and taking everything in concern I think that returning 0 is the best approach. mostly because at this point we are far away from the "problem" to be able to affect the cause.

For example, what you get after dividing two zeroes

ConsoleWrite(0/0 & @CRLF)

You get -1.#IND

What is that? Is that a string. It has some letters. No it's a number

ConsoleWrite(IsNumber(0/0) & @CRLF)

Since don't have option to make numbers containing letters, it is quite obvious that returning zero and raising error is the best (only) approach here.

I obviously didn't know this yesterday and therefore I would agree with Manadar about questioning things. If nothing else it can at least make us (me :P) a bit smarter.

Standardisation, as andybiochem said, is very important. Inconsistencies are not wellcome and should be avoided.

But, nothing is imune to that. For example, speaking of math functions, microsoft has at least one inconsistence and that one is within Atan2 function.

Atan2 - wiki

Atan2 - microsoft office

Atan2 - javascript

Atan2 - msvcrt.dll (link):

Func _ATan2($nY, $nX)
    If $h_DLL <> -1 Then $aResult = DllCall("msvcrt.dll", "double:cdecl", "atan2", "double", $nY, "double", $nX)
    Return $aResult[0]
EndFunc

I will summarize what's on that links:

Definition of Atan2 is very strict as seen at wiki link and MS office sticks to it (so they say) while javascript approach is the same as within msvcrt.dll (C ).

So, office and definition says -1.#IND and the rest of microsoft says 0 for Atan2(0, 0). That is inconsistency.

Function _Atan2 included in Math.au3 has a bug. It's not returning right when both parameters ar below 0.

_Atan2(-1, -1) should be -2.3561944901923, and what we get now is 3.92699081698724

This one returns right:

Func _ATan2(Const $nY, Const $nX)  
    
    If Not IsNumber($nY) Or Not IsNumber($nX) Then Return SetError(1, 0, 0)
    
    Return SetError(0, 0, ATan($nY / $nX) + ((($nY <= 0) And ($nX < 0)) + (($nY > 0) And ($nX < 0)) - 2 * (($nY < 0) And ($nX < 0))) * 3.14159265358979323846)
        
EndFunc

They are as fast and precise as they can be to my knowledge (that actually doesn't mean anything).

I know that most people don't like math but math is very important and these functions are very important to have, if for nothing else then for the sake of completeness.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Great work trancexx

Since you have _Cosh, _Sinh and _Tanh, I also suggest you write their inverse functions, _ACosh, _ASinh and _ATanh. Please check http://en.wikipedia.org/wiki/Hyperbolic_function for their formulas.

Regards.

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Here is a quick one:

; #FUNCTION# ;===============================================================================
;
; Name...........: _Factorial
; Description ...: Returns the factorial of a non-negative integer
; Syntax.........: _Factorial(Const $iX)
; Parameters ....: $iX = a non-negative integer
; Return values .: Success - Returns the factorial of the given number
;                  Failure - Returns 0 and sets @error:
;                  |0 - No error
;                  |1 - $iX is not a non-negative integer
; Author ........: engine
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
;
;==========================================================================================
Func _Factorial(Const $iX)
    If $iX < 0 Or Not IsInt($iX) Then Return SetError(1, 0, 0)
    Local $iF = 1
    For $i = 2 To $iX
        $iF *= $i
    Next
    Return $iF
EndFunc ;==> _Factorial

Check -> http://en.wikipedia.org/wiki/Factorial

Edit: Returns exact values up to $iX = 20. Must be due to an AutoIt limitation or bug.

Edited by engine

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Another suggestion.

In AutoIt you can use "Exp()" instead of define the natural logarithm raised to a number.

For example:

Func _Cosh(Const $nX)
    
    If Not IsNumber($nX) Then Return SetError(1, 0, 0)
    
    Return SetError( 0, 0, ( Exp($nX) + Exp(-$nX) ) / 2 )
    
EndFunc   ;==>_Cosh

Regards.

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

It is. The number is too big to hold in an integer.. I wouldn't know how to work around it.

AutoIt seems to work with 64 bit integers.

Since:

21! > 2^64

it can't hold the number.

That's my theory.

Edit:

What are the current technical limits of AutoIt v3?

(...)

Number range (integers): 64-bit signed integer.

(...)

Edited by engine

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

It is. The number is too big to hold in an integer.. I wouldn't know how to work around it.

This increases the possibility up to 170. But the precision might be unacceptable.

; #FUNCTION# ;===============================================================================
;
; Name...........: _Factorial
; Description ...: Returns the factorial of a non-negative integer
; Syntax.........: _Factorial(Const $iX)
; Parameters ....: $iX = a non-negative integer
; Return values .: Success - Returns the factorial of the given number
;                  Failure - Returns 0 and sets @error:
;                  |0 - No error
;                  |1 - $iX is not a non-negative integer
; Author ........: engine
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......:
;
;==========================================================================================
Func _Factorial(Const $iX)
    If $iX < 0 Or Not IsInt($iX) Then Return SetError(1, 0, 0)
    If $iX > 20 Then
        Local $iF = 1E0
    Else
        Local $iF = 1
    EndIf
    For $i = 2 To $iX
        $iF *= $i
    Next
    Return $iF
EndFunc ;==> _Factorial

My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Link to comment
Share on other sites

Another suggestion.

In AutoIt you can use "Exp()" instead of define the natural logarithm raised to a number.

For example:

Func _Cosh(Const $nX)
    
    If Not IsNumber($nX) Then Return SetError(1, 0, 0)
    
    Return SetError( 0, 0, ( Exp($nX) + Exp(-$nX) ) / 2 )
    
EndFunc   ;==>_CoshoÝ÷ Ù j·lþ«¨µà,"Æ¢u·¢·¬¥çjwi­ç"²*'j·®ç"jQnËb¢q1¦+'z+az·Ú²×«é­ç"±ëaj{¬x(¥êÚ¶Ú×(ËZÑh­ìZ^vÞÞÛwª¹©l÷¾8óMøã­¸óÝ6ëM4ß·Û¯8óm½ï»ï®=ßÎûë7ëM:÷¾·çtßm»óMxïMz÷½:ßÍu÷}}ã¿tÛÍ8×­zã~Ñ1§^µ¢·µëWª¹©l÷Í´ë½=Ûm;×~zçͼóݶӿtó¾9Û½tó­ýëz×ß}çôë{çOzëNúë}wë~÷ïõëÍ»ß^üß½öïm|ÛÝ·÷¿

♡♡♡

.

eMyvnE

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...