The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::Logic::Ternary::Object - role providing trit introspection

VERSION

This documentation refers to version 0.003 of Math::Logic::Ternary::Object.

SYNOPSIS

  package Foo;

  use Role::Basic qw(with);
  with qw(Math::Logic::Ternary::Object);

  sub Trit      { ... }
  sub Trits     { ... }
  sub Rtrits    { ... }
  sub Sign      { ... }
  sub as_int    { ... }
  sub as_int_u  { ... }
  sub as_int_v  { ... }
  sub as_string { ... }
  sub is_equal  { ... }
  sub res_mod3  { ... }

DESCRIPTION

The role Math::Logic::Ternary::Object defines a common interface for trit container objects to retrieve individual trits, numerical values and a string representation.

Classes consuming the role Math::Logic::Ternary::Object have to implement these methods:

Trit

Take an integer index, return a single trit, as if the object was an array of trits. Return nil if the index exceeds the container size.

Trits

In list context, return all trits in the container, from least to most significant, including "leading" (most significant) zeroes. In scalar context, return the size of the container in trits.

Rtrits

In list context, return all trits in the container, from least to most significant, without "leading" (most significant) zeroes. In scalar context, return the number of trits in the container not counting leading zeroes.

Sign

Return the sign trit of the balanced ternary integer number the object represents. This is equivalent to the most significant non-zero trit if that exists or zero (nil) otherwise.

as_int

Return the balanced ternary integer number the object represents.

as_int_u

Return the unsigned base 3 integer number the object represents.

as_int_v

Return the base(-3) integer number the object represents.

as_string

Return a string representation of the object.

For containers, this may be a @ sigil, followed by a sequence of n | t | f characters for all trits in the container including leading zeroes, from most to least significant trit.

For single trits, this may be a $ sigil followed by the name of the trit.

is_equal

Take another object, return a boolean value whether both objects contain the same sequence of trits (ignoring most significant zeroes, so that containers of different size may compare as equal).

res_mod3

Return the least significant trit as an unsigned integer (0, 1, or 2).

Exports

None.

SEE ALSO

AUTHOR

Martin Becker <becker-cpan-mp@cozap.com>

COPYRIGHT AND LICENSE

Copyright (c) 2012-2017 by Martin Becker, Blaubeuren. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.0 or, at your option, any later version of Perl 5 you may have available.