Skip to content

Commit

Permalink
Merge pull request #22 from Kaputchino/master
Browse files Browse the repository at this point in the history
Add mathematical functions
  • Loading branch information
sam-astro committed May 25, 2022
2 parents 1ad7019 + b321a36 commit 70a2c8c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
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.
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.
* Drag and drop any .ZS script directly onto the executable.
* Use command line, providing path to interpreter and then to script like so:
`> ./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.
### Linux
1. Install requirements:
Expand Down
67 changes: 66 additions & 1 deletion ZSharp/ZS.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using namespace std;

std::string ZSContents = R"(
////////////////////////////////////////////////////////////////////////////////
// ↓ DEFAULT BUILTIN ↓
// Default variables, can be overwritten
// if re-initialized or changed
float PI = 3.14159265358979323846264338
Expand Down Expand Up @@ -138,9 +141,71 @@ func GetKey(keyName)
return b
}
// WIP
//func 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)
}
)"
;
;

0 comments on commit 70a2c8c

Please sign in to comment.