![]() |
|
|
#2421 |
|
Aug 2006
10111010110112 Posts |
Oh, another general tip: don't use variables in a function without declaring them with my(). You'll avoid a lot of trouble this way.
So I wrote Code:
cw(w)={
my(v=Vecsmall(w));
sum(i=1,#v,v[i]-64)
};
Code:
cw(w)={
v=Vecsmall(w);
sum(i=1,#v,v[i]-64)
};
Code:
v=1;w=cw("ABC");v
There are other reasons to use my() other than just variable clobbering. For example, the scripts tend to be faster and are compatible with gp2c. But don't worry about the reasoning, just get into the habit of doing this.
|
|
|
|
|
|
#2422 |
|
Jul 2013
Brazil
19 Posts |
Oh, Thanks for the hint, I was wondering why was returning Vectorsmall(x).
I have a few more questions. 1) Does PARI has a friendly developing interface? I have found "Pari-tty", however, its not up-to-date (it runs only with PARI 2.2.11). 2) Somehow can I return the decimal fraction of a number? For exemple: Once again, Thank you. Last fiddled with by ismillo on 2013-07-26 at 22:41 |
|
|
|
|
|
#2423 | ||
|
Aug 2006
3·1,993 Posts |
Quote:
![]() Quote:
Code:
fracpart(x)=x - floor(x) Code:
fracpart(x)=x - x\1 |
||
|
|
|
|
|
#2424 |
|
Jul 2013
Brazil
19 Posts |
.-.
I have several issues with Command Prompt interface , such as copy and paste (right-click all time is a lame). Does not show all the code writen before the last hundred lines (up arrow key all time is a lame). I don't know if it's because I'm not used to, or lazy, or too new in this area. Or all of them. Btw, I did't even think in doing this function. Now it's 1am, later today I'll try something with this. Thanks. Last fiddled with by ismillo on 2013-07-27 at 03:44 |
|
|
|
|
|
#2425 | ||
|
Aug 2006
3×1,993 Posts |
Quote:
Quote:
See http://math.crg4.com/pari/highlight.html for syntax highlighting if your text editor does not have this already. If you're on a friend's computer (or at school, work, etc. and can't install programs) you can get syntax highlighting online at pastebin.com. |
||
|
|
|
|
|
#2426 | |||
|
Jul 2013
Brazil
19 Posts |
Quote:
Quote:
Quote:
Using "frac(x)" I could do that: Code:
a=1.2345; f=frac(a)*10^4; c=ceil(f) |
|||
|
|
|
|
|
#2427 | ||
|
Aug 2006
3×1,993 Posts |
Quote:
In addition to the editors I mentioned explicitly, anything GtkSourceView-based or GeSHi-based should work as well, though you may need an update or download for it. Alternately you can use a different editor for GP than for your other work -- I did this for Ruby, where I found an editor that was particularly good for it even though I didn't prefer it overall. Or just use your existing one without highlighting, it's not that big of a deal unless you work with it a lot. Quote:
I don't quite understand what you need but this seems very easy to automate. |
||
|
|
|
|
|
#2428 | ||
|
Jul 2013
Brazil
19 Posts |
Quote:
The truth is, my problem isn't highlight syntax, my problem is the lack of freedom in PARI interface. I do like very much see what I'm writing and testing them while I writing. Quote:
Something like this: Code:
gp>a=1.23456; gp>c=digits(ceil(frac(a)*((#Str(a)-#Str(a))+10^10))) %1 = [2,3,4,5,6,0,0,0,0,0,0] It works awesome with numbers like Somehow if I could remove the 0s from the last digits, but the 0s must be in a large sequence, otherwise it would break the number. Last fiddled with by ismillo on 2013-07-27 at 23:15 |
||
|
|
|
|
|
#2429 | ||
|
Aug 2006
3·1,993 Posts |
I don't own a copy. You might be able to make your own syntax highlighting file by following their instructions here:
http://docs.sublimetext.info/en/late...yntaxdefs.html if you like. Quote:
gp uses readline to provide these facilities and it works very well for me. It lets you edit previous lines, has tab completion (type "isps" and hit TAB to get "ispseudoprime()"), and so forth. Quote:
Code:
fracpart(x)={
x-=x/1;
my(t=precision(x),s=log(x)\log(10),v=vector(t));
x/=10^s;
for(i=1,t,
v[i]=x\1;
x=10*(x-v[i])
);
v
};
|
||
|
|
|
|
|
#2430 | ||
|
Jul 2013
Brazil
19 Posts |
Quote:
It's basically this but, it's ok soon or later I'll get used to it. :D Quote:
"*** log: domain error in log: argument = 0" It's pointed to "s=log(x)". Edit: I think the error is here "x-=x/1", it should be "x-=x\1;", I guess? When I changed common slash to backslash it's gave no error, and the result is giving the digits normally, however the last digits is "0" or "9". Last fiddled with by ismillo on 2013-07-28 at 00:42 |
||
|
|
|
|
|
#2431 |
|
Aug 2006
597910 Posts |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |