mirror of
https://github.com/sam-astro/Z-Sharp.git
synced 2025-12-11 16:22:12 +00:00
Merge pull request #22 from Kaputchino/master
Add mathematical functions
This commit is contained in:
commit
70a2c8ce7e
@ -13,12 +13,13 @@ Downloading or installing is very simple, here is how depending on your version
|
|||||||
1. Navigate to [the most recent release](https://github.com/sam-astro/Z-Sharp/releases) and download `ZSharp-Win-Installer.zip`.
|
1. Navigate to [the most recent release](https://github.com/sam-astro/Z-Sharp/releases) and download `ZSharp-Win-Installer.zip`.
|
||||||
2. Unzip `ZSharp-Win-Installer.zip` and open the unzipped folder.
|
2. Unzip `ZSharp-Win-Installer.zip` and open the unzipped folder.
|
||||||
3. Inside is a single file titled `ZSharp-Setup.exe`. Run it, and follow the setup instructions.
|
3. Inside is a single file titled `ZSharp-Setup.exe`. Run it, and follow the setup instructions.
|
||||||
4. Now that it is installed, there are a few ways to use it:
|
4. If it fails to run, make sure the `MS Visual Runtime and MSVC C++ Redistribute` are installed. You can download them [here from Microsoft](https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist)
|
||||||
|
5. Now that it is installed, there are a few ways to use it:
|
||||||
* (recommended) Any ZSharp file that ends with .ZS will automatically be associated with the interpreter. Just double-click it, and the interpreter will run.
|
* (recommended) Any ZSharp file that ends with .ZS will automatically be associated with the interpreter. Just double-click it, and the interpreter will run.
|
||||||
* Drag and drop any .ZS script directly onto the executable.
|
* Drag and drop any .ZS script directly onto the executable.
|
||||||
* Use command line, providing path to interpreter and then to script like so:
|
* Use command line, providing path to interpreter and then to script like so:
|
||||||
`> ./ZSharp.exe ./Pong-Example-Project/script.zs`
|
`> ./ZSharp.exe ./Pong-Example-Project/script.zs`
|
||||||
5. Feel free to use and edit the `Pong-Example-Project`. It is a single script called `script.zs`, and you can open it with any of the methods above. It is also located on the releases page.
|
6. Feel free to use and edit the `Pong-Example-Project`. It is a single script called `script.zs`, and you can open it with any of the methods above. It is also located on the releases page.
|
||||||
> If you don't want to install ZSharp on your device, or you want easier acces to the executable and .DLLs, another version is provided called `ZS_Win_Base_Raw.zip`. This just contains all of the files the installer puts on your computer.
|
> If you don't want to install ZSharp on your device, or you want easier acces to the executable and .DLLs, another version is provided called `ZS_Win_Base_Raw.zip`. This just contains all of the files the installer puts on your computer.
|
||||||
### Linux
|
### Linux
|
||||||
1. Install requirements:
|
1. Install requirements:
|
||||||
|
|||||||
67
ZSharp/ZS.h
67
ZSharp/ZS.h
@ -3,6 +3,9 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
std::string ZSContents = R"(
|
std::string ZSContents = R"(
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// ↓ DEFAULT BUILTIN ↓
|
||||||
|
|
||||||
// Default variables, can be overwritten
|
// Default variables, can be overwritten
|
||||||
// if re-initialized or changed
|
// if re-initialized or changed
|
||||||
float PI = 3.14159265358979323846264338
|
float PI = 3.14159265358979323846264338
|
||||||
@ -138,9 +141,71 @@ func GetKey(keyName)
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WIP
|
||||||
//func SplitThread(function)
|
//func SplitThread(function)
|
||||||
//{
|
//{
|
||||||
// ZS.System.SplitThread(function)
|
// ZS.System.SplitThread(function)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// ↓ MADE BY KAPUTCHINO ↓
|
||||||
|
|
||||||
|
// Return the number of combinations
|
||||||
|
func Comb(n, r)
|
||||||
|
{
|
||||||
|
return Perm(n, r) / Fac(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the factorial of a number
|
||||||
|
func Fac(x)
|
||||||
|
{
|
||||||
|
int r = 1
|
||||||
|
while x > 1
|
||||||
|
{
|
||||||
|
r = r * x
|
||||||
|
x = x - 1
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return exp(x) by using the taylor method, not extremly accurate
|
||||||
|
func TaylorExp(x)
|
||||||
|
{
|
||||||
|
float sum = 0
|
||||||
|
float term = 1
|
||||||
|
int i = 1
|
||||||
|
float sumterm = 1
|
||||||
|
while sum != sumterm
|
||||||
|
{
|
||||||
|
sum = sumterm
|
||||||
|
term = term * x / i
|
||||||
|
i = i + 1
|
||||||
|
sumterm = sumterm + term
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the number of permutations
|
||||||
|
func Perm(n, r)
|
||||||
|
{
|
||||||
|
if n < 0
|
||||||
|
{
|
||||||
|
ZS.System.PrintLine("n muss be superior or equal to 0")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if r < 0
|
||||||
|
{
|
||||||
|
ZS.System.PrintLine("r muss be superior or equal to 0")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if r > n
|
||||||
|
{
|
||||||
|
ZS.System.PrintLine("r muss be inferor or equal to n")
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return Fac(n) / Fac(n - r)
|
||||||
|
}
|
||||||
|
|
||||||
)"
|
)"
|
||||||
;
|
;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user