Elliptic curve arithmetic: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed whitespace, optimized some functions, indented the output, used a template for the output section.) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: clarify package vs local variables, output fixes) |
||
Line 873: | Line 873: | ||
{{trans|C}} |
{{trans|C}} |
||
<lang perl>package EC; |
<lang perl>package EC; |
||
⚫ | |||
{ |
{ |
||
⚫ | |||
package EC::Point; |
package EC::Point; |
||
sub new { my $class = shift; bless [ @_ ], $class } |
sub new { my $class = shift; bless [ @_ ], $class } |
||
Line 906: | Line 906: | ||
package Test; |
package Test; |
||
my $ |
my $p = +EC::Point->new(-($EC::B - 1)**(1/3), 1); |
||
my $ |
my $q = +EC::Point->new(-($EC::B - 4)**(1/3), 2); |
||
my $s = $p + $q, "\n"; |
|||
print "$_\n" for $ |
print "$_\n" for $p, $q, $s; |
||
print "check |
print "check alignment... "; |
||
print abs(($ |
print abs(($q->x - $p->x)*(-$s->y - $p->y) - ($q->y - $p->y)*($s->x - $p->x)) < 0.001 |
||
? "ok" : "wrong"; |
? "ok" : "wrong";</lang> |
||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>EC-point at x=-1.817121, y=1.000000 |
<pre>EC-point at x=-1.817121, y=1.000000 |
||
EC-point at x=-1.442250, y=2.000000 |
EC-point at x=-1.442250, y=2.000000 |
||
EC-point at x=10.375375, y=-33.524509 |
EC-point at x=10.375375, y=-33.524509 |
||
check |
check alignment... ok |
||
</pre> |
</pre> |
||