| 1 | package CXC::Number::Sequence::Types; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Type::Tiny types for CXC::Number::Sequence | ||||||||||
| 4 | |||||||||||
| 5 | 13 | ▶ | use v5.28; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 13 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 13 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 13 | our $VERSION = '0.12'; | |||||||||
| 10 | |||||||||||
| 11 | 13 | ▶ | use Math::BigInt upgrade => 'Math::BigFloat'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 13 | ▶ | use Math::BigFloat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 13 | ▶ | use Type::Utils -all; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 13 | ▶ | use Types::Standard qw[ Num Int Enum Tuple Any InstanceOf Dict ArrayRef Value ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 13 | ▶ | use Types::Common::Numeric qw[ PositiveNum PositiveOrZeroNum PositiveInt ]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 13 | use Type::Library -base, -declare => qw( | |||||||||
| 18 | Alignment | ||||||||||
| 19 | Sequence | ||||||||||
| 20 | Spacing | ||||||||||
| 21 | Ratio | ||||||||||
| 22 | 13 | ▶ | ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 13 | ▶ | BEGIN { extends 'CXC::Number::Types' } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 9 | ▶ | declare Alignment, as Tuple [ BigNum, BigPositiveOrZeroNum ], where { $_->[1] < 1 }, coercion => 1; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | coerce Alignment, from Num, via { [ Math::BigFloat->new( $_ ), Math::BigFloat->new( 0.5 ) ] }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | |||||||||||
| 49 | declare Sequence, as ArrayRef [ BigNum, 2 ], where { | ||||||||||
| 50 | 17 | ▶ | my $arr = $_; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 51 | 17 | ▶ | $arr->[$_] < $arr->[ $_ + 1 ] || return for 0 .. ( $arr->@* - 2 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 11 | 1; | |||||||||
| 53 | }, message { | ||||||||||
| 54 | 9 | ▶ | ArrayRef( [ BigNum, 2 ] )->validate( $_ ) | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 55 | or 'Must be an array of monotonically increasing numbers with at lest two elements' | ||||||||||
| 56 | 13 | }, coercion => 1; | |||||||||
| 57 | |||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | |||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | declare Spacing, as BigNum, | ||||||||||
| 66 | 27 | ▶ | where { $_ != 0 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 67 | 1 | ▶ | message { BigNum->validate( $_ ) or 'Must be a non-zero number' }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 68 | 13 | coercion => 1; | |||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | |||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | declare Ratio, as BigNum, | ||||||||||
| 78 | 30 | ▶ | where { $_ > 0 && $_ != 1 }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 79 | 3 | ▶ | message { BigNum->validate( $_ ) or 'Number must be > 0 && != 1' }, | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||
| 80 | 13 | coercion => 1; | |||||||||
| 81 | |||||||||||
| 82 | # | ||||||||||
| 83 | # This file is part of CXC-Number | ||||||||||
| 84 | # | ||||||||||
| 85 | # This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. | ||||||||||
| 86 | # | ||||||||||
| 87 | # This is free software, licensed under: | ||||||||||
| 88 | # | ||||||||||
| 89 | # The GNU General Public License, Version 3, June 2007 | ||||||||||
| 90 | # | ||||||||||
| 91 | |||||||||||
| 92 | 13 | 1; | |||||||||
| 93 | |||||||||||
| 94 | __END__ | ||||||||||
| 95 | |||||||||||
| 96 | =pod | ||||||||||
| 97 | |||||||||||
| 98 | =for :stopwords Diab Jerius Smithsonian Astrophysical Observatory bignum | ||||||||||
| 99 | |||||||||||
| 100 | =head1 NAME | ||||||||||
| 101 | |||||||||||
| 102 | CXC::Number::Sequence::Types - Type::Tiny types for CXC::Number::Sequence | ||||||||||
| 103 | |||||||||||
| 104 | =head1 VERSION | ||||||||||
| 105 | |||||||||||
| 106 | version 0.12 | ||||||||||
| 107 | |||||||||||
| 108 | =head1 TYPES | ||||||||||
| 109 | |||||||||||
| 110 | =head2 Alignment | ||||||||||
| 111 | |||||||||||
| 112 | A Tuple containing two elements, the first of which is a C<BigNum>, | ||||||||||
| 113 | the second of which is a C<BigNum> in the range [0,1). | ||||||||||
| 114 | |||||||||||
| 115 | =head2 Sequence | ||||||||||
| 116 | |||||||||||
| 117 | A array of numbers with at lest two members which is sorted by increasing value | ||||||||||
| 118 | |||||||||||
| 119 | =head2 Spacing | ||||||||||
| 120 | |||||||||||
| 121 | A non-zero BigNum | ||||||||||
| 122 | |||||||||||
| 123 | =head2 Ratio | ||||||||||
| 124 | |||||||||||
| 125 | A positive number greater than 1. | ||||||||||
| 126 | |||||||||||
| 127 | =head1 INTERNALS | ||||||||||
| 128 | |||||||||||
| 129 | =head1 SUPPORT | ||||||||||
| 130 | |||||||||||
| 131 | =head2 Bugs | ||||||||||
| 132 | |||||||||||
| 133 | Please report any bugs or feature requests to bug-cxc-number@rt.cpan.org or through the web interface at: L<https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-Number> | ||||||||||
| 134 | |||||||||||
| 135 | =head2 Source | ||||||||||
| 136 | |||||||||||
| 137 | Source is available at | ||||||||||
| 138 | |||||||||||
| 139 | https://gitlab.com/djerius/cxc-number | ||||||||||
| 140 | |||||||||||
| 141 | and may be cloned from | ||||||||||
| 142 | |||||||||||
| 143 | https://gitlab.com/djerius/cxc-number.git | ||||||||||
| 144 | |||||||||||
| 145 | =head1 SEE ALSO | ||||||||||
| 146 | |||||||||||
| 147 | Please see those modules/websites for more information related to this module. | ||||||||||
| 148 | |||||||||||
| 149 | =over 4 | ||||||||||
| 150 | |||||||||||
| 151 | =item * | ||||||||||
| 152 | |||||||||||
| 153 | L<CXC::Number|CXC::Number> | ||||||||||
| 154 | |||||||||||
| 155 | =back | ||||||||||
| 156 | |||||||||||
| 157 | =head1 AUTHOR | ||||||||||
| 158 | |||||||||||
| 159 | Diab Jerius <djerius@cpan.org> | ||||||||||
| 160 | |||||||||||
| 161 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 162 | |||||||||||
| 163 | This software is Copyright (c) 2019 by Smithsonian Astrophysical Observatory. | ||||||||||
| 164 | |||||||||||
| 165 | This is free software, licensed under: | ||||||||||
| 166 | |||||||||||
| 167 | The GNU General Public License, Version 3, June 2007 | ||||||||||
| 168 | |||||||||||
| 169 | =cut | ||||||||||