Jump to content

Calc UDF :)


Zibit
 Share

Recommended Posts

Now this has been quite useful for me in my physics & Gaming scripts though not very success anyway ;) but Theres a lot of ratio's and stuff...

Feel free to do anything u want with it...

Its nothing but math no special scripting or anything :);)

#comments-start
Gravity = gravitational constant
Mass 1 = Object 1's Mass in Kilograms
Mass 2 = Object 2's Mass in Kilograms
Dist = Distance between the 2 objects in Meters
Returns : Force = is the magnitude of the gravitational force between the two point masses. Mesured in Newtons.
#comments-end
Func _Calc_Force($gravity, $mass1, $mass2, $dist)
$force = $gravity*(($mass1*$mass2)/($dist*$dist))
Return $force
EndFunc
#comments-start
Velocity = the tangential velocity of the object.
Radius = the radius of the circle and m is mass of the object.
Mass = Objects Mass
Acceleration = the centripetal (acting towards the center of the circle) acceleration
Returns : Force = The centripetal force
#comments-end
Func _Calc_CircularMotion_Force($vel, $radius, $mass)
$acc = ($vel*$vel)/$radius
$force = $mass*$acc
Return $force
EndFunc
#comments-start
Basic Commands
#comments-end
Func _Calc_Sectomin($sec)
Return ($sec/60)
EndFunc
Func _Calc_Sectohour($sec)
Return (($sec/60)/60)
EndFunc
Func _Calc_Sectoday($sec)
Return ((($sec/60)/60)/24)
EndFunc
Func _Calc_Sectoweek($sec)
Return (((($sec/60)/60)/24)/7)
EndFunc
Func _Calc_Sectomonth($sec)
Return ((((($sec/60)/60)/24))/30)
EndFunc
Func _Calc_Sectoyear($sec)
Return (((((($sec/60)/60)/24))/30)/12)
EndFunc
Func _Calc_Mintosec($min)
Return ($min*60)
EndFunc
Func _Calc_Mintohour($min)
Return ($min/60)
EndFunc
Func _Calc_Mintoday($min)
Return (($min/60)/24)
EndFunc
Func _Calc_Mintoweek($min)
Return ((($min/60)/24)/7)
EndFunc
Func _Calc_Mintomonth($min)
Return (((($min/60)/24))/30)
EndFunc
Func _Calc_Mintoyear($min)
Return ((((($min/60)/24))/30)/12)
EndFunc
Func _Calc_Hourtosec($hour)
Return (($hour*60)*60)
EndFunc
Func _Calc_Hourtomin($hour)
Return (($hour*60))
EndFunc
Func _Calc_Hourtoday($hour)
Return (($hour/24))
EndFunc
Func _Calc_Hourtoweek($hour)
Return (($hour/24)/7)
EndFunc
Func _Calc_Hourtomonth($hour)
Return ((($hour/24))/30)
EndFunc
Func _Calc_Hourtoyear($hour)
Return (((($hour/24))/30)/12)
EndFunc
Func _Calc_Daytosec($day)
Return ((($day*24)*60)*60)
EndFunc
Func _Calc_Daytomin($day)
Return ((($day*24)*60))
EndFunc
Func _Calc_Daytohour($day)
Return ($day*24)
EndFunc
Func _Calc_Daytoweek($day)
Return ($day/7)
EndFunc
Func _Calc_Daytomonth($day)
Return ($day/30)
EndFunc
Func _Calc_Daytoyear($day)
Return (($day/30)/12)
EndFunc
Func _Calc_Weektosec($week)
Return ((((($week*7)*24)*60)*60))
EndFunc
Func _Calc_Weektomin($week)
Return (((($week*7)*24)*60))
EndFunc
Func _Calc_Weektohour($week)
Return (($week*7)*24)
EndFunc
Func _Calc_Weektoday($week)
Return ($week*7)
EndFunc
Func _Calc_Weektomonth($week)
Return ($week/30)
EndFunc
Func _Calc_Weektoyear($week)
Return (($week/30)/12)
EndFunc
Func _Calc_Yeartosec($year)
Return ((((($year*12)*30)*24)*60)*60)
EndFunc
Func _Calc_Yeartomin($year)
Return (((($year*12)*30)*24)*60)
EndFunc
Func _Calc_Yeartohour($year)
Return ((($year*12)*30)*24)
EndFunc
Func _Calc_Yeartoday($year)
Return (($year*12)*30)
EndFunc
Func _Calc_Yeartoweek($year)
Return (($year*12)*7)
EndFunc
Func _Calc_Yeartomonth($year)
Return ($year*12)
EndFunc
Func _Calc_KmToLy($km)
Return ($km/9460730472580.8)
EndFunc
Func _Calc_LyToKm($ly)
Return ($ly*9460730472580.8)
EndFunc
Func _Calc_Bytetokb($byte)
Return ($byte/1000)
EndFunc
Func _Calc_Bytetomb($byte)
Return (($byte/1000)/1000)
EndFunc
Func _Calc_Bytetogb($byte)
Return ((($byte/1000)/1000)/1000)
EndFunc
Func _Calc_Bytetotb($byte)
Return ((($byte/1000)/1000)/1000)
EndFunc
Func _Calc_Bytetopb($byte)
Return (((($byte/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Bytetoeb($byte)
Return ((((($byte/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Bytetozb($byte)
Return (((((($byte/1000)/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Bytetoyb($byte)
Return ((((((($byte/1000)/1000)/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Kbtobyte($kb)
Return ($kb*1000)
EndFunc
Func _Calc_Kbtomb($kb)
Return ($kb/1000)
EndFunc
Func _Calc_Kbtogb($kb)
Return (($kb/1000)/1000)
EndFunc
Func _Calc_Kbtotb($kb)
Return ((($kb/1000)/1000)/1000)
EndFunc
Func _Calc_Kbtopb($kb)
Return (((($kb/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Kbtoeb($kb)
Return ((((($kb/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Kbtozb($kb)
Return (((((($kb/1000)/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Kbtoyb($kb)
Return ((((((($kb/1000)/1000)/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Mbtobyte($mb)
Return (($mb*1000)*1000)
EndFunc
Func _Calc_Mbtokb($mb)
Return ($mb*1000)
EndFunc
Func _Calc_Mbtogb($mb)
Return ($mb/1000)
EndFunc
Func _Calc_Mbtotb($mb)
Return (($mb/1000)/1000)
EndFunc
Func _Calc_Mbtopb($mb)
Return ((($mb/1000)/1000)/1000)
EndFunc
Func _Calc_Mbtoeb($mb)
Return (((($mb/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Mbtozp($mb)
Return ((((($mb/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Mbtoyb($mb)
Return (((((($mb/1000)/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Gbtobyte($gb)
Return ((($gb*1000)*1000)*1000)
EndFunc
Func _Calc_Gbtokb($gb)
Return (($gb*1000)*1000)
EndFunc
Func _Calc_Gbtomb($gb)
Return ($gb*1000)
EndFunc
Func _Calc_Gbtotb($gb)
Return ($gb/1000)
EndFunc
Func _Calc_Gbtopb($gb)
Return (($gb/1000)/1000)
EndFunc
Func _Calc_Gbtoeb($gb)
Return ((($gb/1000)/1000)/1000)
EndFunc
Func _Calc_Gbtozp($gb)
Return (((($gb/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Gbtoyb($gb)
Return ((((($gb/1000)/1000)/1000)/1000)/1000)
EndFunc
Func _Calc_Tbtobyte($tb)
Return (((($tb*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Tbtokb($tb)
Return ((($tb*1000)*1000)*1000)
EndFunc
Func _Calc_Tbtomb($tb)
Return (($tb*1000)*1000)
EndFunc
Func _Calc_Tbtogb($tb)
Return ($tb*1000)
EndFunc
Func _Calc_Tbtopb($tb)
Return ($tb/1000)
EndFunc
Func _Calc_Tbtozp($tb)
Return (($tb/1000)/1000)
EndFunc
Func _Calc_Tbtoyb($tb)
Return ((($tb/1000)/1000)/1000)
EndFunc
Func _Calc_Pbtobyte($pb)
Return ((((($pb*1000)*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Pbtokb($pb)
Return (((($pb*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Pbtomb($pb)
Return ((($pb*1000)*1000)*1000)
EndFunc
Func _Calc_Pbtogb($pb)
Return (($pb*1000)*1000)
EndFunc
Func _Calc_Pbtotb($pb)
Return ($pb*1000)
EndFunc
Func _Calc_Pbtozp($pb)
Return ($pb/1000)
EndFunc
Func _Calc_Pbtoyb($pb)
Return (($pb/1000)/1000)
EndFunc
Func _Calc_Zptobyte($zb)
Return (((((($zp*1000)*1000)*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Zptokb($zb)
Return ((((($zb*1000)*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Zptomb($zb)
Return (((($zb*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Zptogb($zb)
Return ((($zb*1000)*1000)*1000)
EndFunc
Func _Calc_Zptotb($zb)
Return (($zb*1000)*1000)
EndFunc
Func _Calc_Zptopb($zb)
Return ($zb*1000)
EndFunc
Func _Calc_Zptoyb($zb)
Return ($zb/1000)
EndFunc
Func _Calc_Ybtobyte($yb)
Return ((((((($yb*1000)*1000)*1000)*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Ybtokb($yb)
Return (((((($yb*1000)*1000)*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Ybtomb($yb)
Return ((((($yb*1000)*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Ybtogb($yb)
Return (((($yb*1000)*1000)*1000)*1000)
EndFunc
Func _Calc_Ybtotb($yb)
Return ((($yb*1000)*1000)*1000)
EndFunc
Func _Calc_Ybtopb($yb)
Return (($yb*1000)*1000)
EndFunc
Func _Calc_Ybtozp($yb)
Return ($yb*1000)
EndFunc
Func _Calc_Mtokm($m)
Return ($m/1000)
EndFunc
Func _Calc_Kmtom($km)
Return ($km*1000)
EndFunc
Func _Calc_Mtocm($m)
Return ($m*100)
EndFunc
Func _Calc_Cmtom($cm)
Return ($cm/100)
EndFunc
Func _Calc_Bits($bit)
Return (2^$bit)
EndFunc
#comments-start-------------------------------------------------------------------------------------------------------
    Function: Average Finder
    Fully independent function that takes in parameters delimited with comma and finds the average.
        Usage:
        ("num1,num2,...,numN") NOT ("num1","num2",...,"numN")
        Example: MsgBox(0,"","Your average is: "&_findAvg("1,2,5,34,64,74,23"))
#comments-end-------------------------------------------------------------------------------------------------------
Func _Calc_FindAvg($nums)

    $chk = StringRight($nums, 1)
    If $chk == "," Then $nums = StringTrimRight($nums, 1)
    If StringInStr($nums, ",") == 0 Then
        SetError(1) ;1 = error
    EndIf
    
    $sData = StringSplit($nums, ",")
    $ans = 0
    $i = 1
    While $i <= $sData[0]
        $ans = $ans + $sData[$i]
        $i += 1
    WEnd
    $ans = $ans / $sData[0]
    Return ($ans)
EndFunc  
Func _Calc_OnePercent($num, $perc)
Return (($num * $perc) / 100)
EndFunc

Func _Calc_NumOutOfNumPercent($num1, $num2)
Return(($num1 / $num2) * 100)
EndFunc

Update 18. Sept

* Added NumOutOfNum Percent Calc

Update 16. Sept

* Added TheSaint's Percentage Calc

Update 15. Sept

* Added Foxhound's Average Function

Edited by Zibit
Link to comment
Share on other sites

Nice job. This got me fooling around and I made another function to find average:

#comments-start-------------------------------------------------------------------------------------------------------
    Function: Average Finder
    Fully independent function that takes in parameters delimited with comma and finds the average.
        Usage:
        ("num1,num2,...,numN") NOT ("num1","num2",...,"numN")
        Example: MsgBox(0,"","Your average is: "&_findAvg("1,2,5,34,64,74,23"))
#comments-end-------------------------------------------------------------------------------------------------------
Func _findAvg($nums)

    $chk = StringRight($nums, 1)
    If $chk == "," Then $nums = StringTrimRight($nums, 1)
    If StringInStr($nums, ",") == 0 Then
        SetError(1) ;1 = error
    EndIf
    
    $sData = StringSplit($nums, ",")
    $ans = 0
    $i = 1
    While $i <= $sData[0]
        $ans = $ans + $sData[$i]
        $i += 1
    WEnd
    $ans = $ans / $sData[0]
    Return ($ans)
EndFunc

Also there are simple errors around line 280 putting $zb instead of $zp.

Good work!

Edited by Foxhound
Link to comment
Share on other sites

Very nice, thanks for sharing.

I recommend however, that more capitalization is easier on the eye & brain.

i.e.

_Calc_SecToMin instead of _Calc_Sectomin

_Calc_SecToHour etc

P.S. And actually, it's 1024 not 1000 for transposing kilobytes, Megabytes, etc. ;)

P.S.S. On my quick scan through, I didn't notice an option for doing percentages, which is no big deal, but it could be handy.

$perc = GetPercentageResult(150, 10, 0, 1)

Func GetPercentageResult($tot, $que, $rnd, $ret)

$perc = (($que * 100) + $que) / ($tot + ($tot * 100))

$perc = $perc * 100

If $ret = 2 Then

$perc = StringRegExpReplace($perc, "[a-z]", "")

$perc = StringReplace($perc, "-", "")

$perc = 100 - $perc

EndIf

If $rnd <> "" And $rnd <> -1 Then

$perc = Round($perc, $rnd)

EndIf

Return $perc

EndFunc ;=> GetPercentageResult

or somesuch.

$tot = total amount

$que = query amount

$rnd = round to this many decimals (-1 or nothing (not 0) means don't round).

$ret = return or result (1 = used, 2 = remaining)

The String replace stuff is just so both aspects work for crazy numbers ... even though you aren't getting a true result.

Am I right in presuming Ly stands for Miles ... if so, why not use Miles?

Abbreviations are well & good, but to save on just a few characters, when clarity is the price?

Clarity is always best ... thinking may mean time wasting ... and even mistakes!

EDIT

It is never good to remember things off the top just like that ... you inevitably misremember.

So anyway, I replaced the formula with one from my quirky little Percent-O-Meter program.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Very nice, thanks for sharing.

Am I right in presuming Ly stands for Miles ... if so, why not use Miles?

Abbreviations are well & good, but to save on just a few characters, when clarity is the price?

Clarity is always best ... thinking may mean time wasting ... and even mistakes!

'Ly' would be Light Years, I suspect, not Miles. ;)

Link to comment
Share on other sites

yeah light years dont think that mile is about 4 billion kilometers ^^ and ill change the capitals later on class right now ;) yeah ur right about that :) capitals are easier on the eye.. and i think bytes are read as 1000 and bits are 1024. idk wiki it ;) http://en.wikipedia.org/wiki/Byte

Link to comment
Share on other sites

and i think bytes are read as 1000 and bits are 1024.

just for the record:

1 byte = 8 bits

1 kB = (2^10 = 1024) bytes = 8192 bits

1 MB = (2^10 = 1024) kB = (2^20 = 1.048.576) bytes

1 GB = (2^10 = 1024) MB = (2^20 = 1.048.576) kB = (2^30 = 1073741824) bytes

no doubt about this.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

'Ly' would be Light Years, I suspect, not Miles. ;)

Is that right.

I admit to not looking too closely ... only a vague passing interest in the whole topic ... which is not saying it's bad, so don't get me wrong.

It is never good to remember things off the top just like that ... you inevitably misremember.

So anyway, I replaced the formula in Post #4 (above) with one from my quirky little Percent-O-Meter program.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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...