File: conv.t

package info (click to toggle)
pdl 2.005-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,200 kB
  • ctags: 3,301
  • sloc: perl: 14,876; ansic: 7,223; fortran: 3,417; makefile: 54; sh: 16
file content (48 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Test conversions. This is not yet good enough: we need
# nasty test cases,

# 1.9901 - converted to new type semantics + extra test

use PDL::LiteF;

sub ok {
	my $no = shift ;
	my $result = shift ;
	print "not " unless $result ;
	print "ok $no\n" ;
}

sub approx {
	my($a,$b) = @_;
	my $c = abs($a-$b);
	my $d = max($c);
	$d < 0.01;
}

print "1..7\n";

$a = pdl 42.4;

ok(1,$a->get_datatype == 5);

$b = byte $a;

ok(2,$b->get_datatype == 0);
ok(3,$b->at() == 42);

$c = $b * 3;
ok(4,$c->get_datatype == 0); # $c is the same

$d = $b * 600.0;
ok(5,$d->get_datatype == 4); # $d is promoted to float

$pi = 4*atan2(1,1);

$e = $b * $pi;
ok(6,$e->get_datatype == 5); # $e needs to be double to represent result

$f = $b * "-2.2";
ok(7,$f->get_datatype == 5); # $e check strings are handled ok