Math-Symbolic

 view release on metacpan or  search on metacpan

lib/Math/Symbolic/Constant.pm  view on Meta::CPAN

    croak("Math::Symbolic::Constant created with undefined value!")
      if not defined($value);

    my $self = {
        special => '',
        ( ref($proto) ? %$proto : () ),
        value => $value,
        %args,
    };

    bless $self => $class;
}

=head2 Constructor zero

Arguments are treated as key-value pairs of object attributes.
Returns a Math::Symbolic::Constant with value of 0.

=cut

sub zero {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    croak("Uneven number of arguments to zero()") if @_ % 2;

    return(
	    bless {@_, value => 0, special => 'zero' } => $class
	);

#    return $class->new( { @_, value => 0, special => 'zero' } );
}

=head2 Constructor one

Arguments are treated as key-value pairs of object attributes.
Returns a Math::Symbolic::Constant with value of 1.

=cut

sub one {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    croak("Uneven number of arguments to one()") if @_ % 2;

    return(
	    bless {@_, value => 1, special => 'one' } => $class
	);
	
    #return $class->new( { @_, value => 1 } );
}

=head2 Constructor euler

Arguments are treated as key-value pairs of object attributes.
Returns a Math::Symbolic::Constant with value of e, the Euler number.
The object has its 'special' attribute set to 'euler'.

=cut

sub euler {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    croak("Uneven number of arguments to euler()") if @_ % 2;

    return(
	    bless {@_, value => EULER, special => 'euler' } => $class
	);
    
	#return $class->new( { @_, value => EULER, special => 'euler' } );
}

=head2 Constructor pi

Arguments are treated as key-value pairs of object attributes.
Returns a Math::Symbolic::Constant with value of pi.
The object has its 'special' attribute set to 'pi'.

=cut

sub pi {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    croak("Uneven number of arguments to pi()") if @_ % 2;

    return(
	    bless {@_, value => PI, special => 'pi' } => $class
	);
    
	#return $class->new( { @_, value => PI, special => 'pi' } );
}

=head2 Method value

value() evaluates the Math::Symbolic tree to its numeric representation.

value() without arguments requires that every variable in the tree contains

lib/Math/Symbolic/Operator.pm  view on Meta::CPAN

        %args,
    };

    @{ $self->{operands} } =
      map {
        ref($_) =~ /^Math::Symbolic/
          ? $_
          : Math::Symbolic::parse_from_string($_)
      } @{ $self->{operands} };

    bless $self => $class;
}

=head2 Method arity

Returns the operator's arity as an integer.

=cut

sub arity {
    my $self = shift;

lib/Math/Symbolic/Variable.pm  view on Meta::CPAN


    if (    @_ == 1
        and ref( $_[0] ) eq 'Math::Symbolic::Variable' )
    {
        return $_[0]->new();
    }
    elsif ( @_ and not ref( $_[0] ) eq 'HASH' ) {
        my $name  = shift;
        my $value = shift;
        return
          bless { name => $name, value => $value, signature => [@_] } => $class;
    }


    my $self = {
        value     => undef,
        name      => undef,
        signature => [],
        ( ref($proto) ? %$proto : () ),
        ((@_ and ref($_[0]) eq 'HASH') ? %{$_[0]} : ()),
    };

    bless $self => $class;
}

=head2 Method value

value() evaluates the Math::Symbolic tree to its numeric representation.

value() without arguments requires that every variable in the tree contains
a defined value attribute. Please note that this refers to every variable
I<object>, not just every named variable.

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.790 second using v1.00-cache-2.02-grep-82fe00e-cpan-3b7f77b76a6c )