Difference between revisions of "User:Piphi/Asymptote/piphi"
< User:Piphi | Asymptote
(Created page with "<center><asy>label(scale(2)*"The \texttt{piphi} module");</asy></center> My own unofficial Asymptote module with some useful functions: <math>\texttt{string [] array (string...") |
m (pigments) |
||
Line 5: | Line 5: | ||
<math>\texttt{string [] array (string s);}</math> | <math>\texttt{string [] array (string s);}</math> | ||
:This function is actually part of newer versions of Asymptote, but is not supported in 2.32 so I decided to make it. What it does is it takes a string and splits it into individual characters. | :This function is actually part of newer versions of Asymptote, but is not supported in 2.32 so I decided to make it. What it does is it takes a string and splits it into individual characters. | ||
− | < | + | <syntaxhighlight lang="Asymptote">string [] array (string s) { |
string[]strarray; | string[]strarray; | ||
for (int i=0;i<length(s);++i) { | for (int i=0;i<length(s);++i) { | ||
Line 11: | Line 11: | ||
} | } | ||
return strarray; | return strarray; | ||
− | }</ | + | }</syntaxhighlight> |
<math>\texttt{int length (int i);}</math> | <math>\texttt{int length (int i);}</math> | ||
:returns the number of digits in the given integer. | :returns the number of digits in the given integer. | ||
− | < | + | <syntaxhighlight lang="Asymptote">int length (int i) { |
int j=0; | int j=0; | ||
bool brk=false; | bool brk=false; | ||
Line 25: | Line 25: | ||
} while (!brk); | } while (!brk); | ||
return j; | return j; | ||
− | }</ | + | }</syntaxhighlight> |
<math>\texttt{int int (string s);}</math> | <math>\texttt{int int (string s);}</math> | ||
:converts strings into integers. | :converts strings into integers. | ||
− | < | + | <syntaxhighlight lang="Asymptote">int int (string s) { |
string[]a=array(s); | string[]a=array(s); | ||
int b; | int b; | ||
Line 35: | Line 35: | ||
b+=(ascii(a[i])-48)*10**(a.length-i-1); | b+=(ascii(a[i])-48)*10**(a.length-i-1); | ||
return b; | return b; | ||
− | }</ | + | }</syntaxhighlight> |
More to come... | More to come... |
Revision as of 22:12, 30 October 2020
![[asy]label(scale(2)*"The \texttt{piphi} module");[/asy]](http://latex.artofproblemsolving.com/5/6/8/568323f6c37143ff41d868f8a5353b3e7f3cbaca.png)
My own unofficial Asymptote module with some useful functions:
- This function is actually part of newer versions of Asymptote, but is not supported in 2.32 so I decided to make it. What it does is it takes a string and splits it into individual characters.
string [] array (string s) {
string[]strarray;
for (int i=0;i<length(s);++i) {
strarray[i]=substr(s,i,1);
}
return strarray;
}
- returns the number of digits in the given integer.
int length (int i) {
int j=0;
bool brk=false;
do {
++j;
if (i/(10**j) < 1) {
brk=true;
}
} while (!brk);
return j;
}
- converts strings into integers.
int int (string s) {
string[]a=array(s);
int b;
for (int i=0;i<a.length;++i)
b+=(ascii(a[i])-48)*10**(a.length-i-1);
return b;
}
More to come...