1#!/usr/bin/perl
2
3#  Num.pm - A perl representation of numbers
4#  (c) Copyright 1998 Hakan Ardo <hakan@debian.org>
5#
6#  This program is free software; you can redistribute it and/or modify
7#  it under the terms of the GNU General Public License as published by
8#  the Free Software Foundation; either version 2 of the License, or
9#  any later version.
10#
11#  This program is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU General Public License for more details.
15#
16#  You should have received a copy of the GNU General Public License
17#  along with this program; if not, write to the Free Software
18#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20=head1 NAME
21
22  Math::Expr::Num - Represents one number in a parsed expression tree
23
24=head1 SYNOPSIS
25
26  require Math::Expr::Opp;
27  require Math::Expr::Var;
28  require Math::Expr::Num;
29
30  # To represent the expression "x+7":
31  $n=new Math::Expr::Opp("+");
32  $n->SetOpp(0,new Math::Expr::Var("x"));
33  $n->SetOpp(1,new Math::Expr::Num(7));
34  print $n->tostr . "\n";
35
36=head1 DESCRIPTION
37
38  Used by the Math::Expr to represent numbers.
39
40=head1 METHODS
41
42=cut
43
44package Math::Expr::Num;
45use strict;
46
47use Math::Expr::Node;
48use vars qw(@ISA);
49@ISA = qw(Math::Expr::Node);
50
51=head2 $n=new Math::Expr::Num($num)
52
53  Creates a new representation of the number $num.
54
55=cut
56
57sub new {
58	my($class, $val) = @_;
59	my $self = bless { }, $class;
60
61	$self->{'Val'}=$val;
62	$self;
63}
64
65=head2 $n->tostr
66
67  Returns the string representation of the number which in perl is
68  the same as the number itsefle
69
70=cut
71sub tostr {
72	my $self = shift;
73  $self->{'Val'};
74}
75
76sub toText {shift->tostr}
77
78sub strtype {
79  "Real";
80}
81
82sub BaseType {shift->strtype(@_)}
83
84sub _toMathML {
85  my $self = shift;
86  "<mn>".$self->{'Val'}."</mn>";
87}
88
89
90sub SubMatch {
91	my ($self, $rule, $mset) = @_;
92
93  if ($rule->isa('Math::Expr::Var') && $self->BaseType eq $rule->BaseType) {
94		$mset->SetAll($rule->{'Val'},$self);
95		return 1;
96	}
97  if ($rule->isa('Math::Expr::Num') && $self->BaseType eq $rule->BaseType) {
98	return 1;
99  }
100	return 0;
101}
102
103=head2 $n->Copy
104
105Returns a new copy of itself.
106
107=cut
108
109sub _Copy {
110	my $self= shift;
111
112	new Math::Expr::Num($self->{'Val'});
113}
114
115
116=head1 AUTHOR
117
118  Hakan Ardo <hakan@debian.org>
119
120=head1 SEE ALSO
121
122  L<Math::Expr::Opp>
123
124=cut
125
1261;
127