Mercurial > pub > Impl
changeset 408:5c80e33f1218 ref20150831
added 'coarsen' function
author | cin |
---|---|
date | Mon, 07 Sep 2015 01:35:25 +0300 |
parents | c6e90e02dd17 |
children | f7eeafbd33da |
files | lib/IMPL/lang.pm |
diffstat | 1 files changed, 7 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/IMPL/lang.pm Fri Sep 04 19:40:23 2015 +0300 +++ b/lib/IMPL/lang.pm Mon Sep 07 01:35:25 2015 +0300 @@ -6,9 +6,10 @@ use IMPL::_core::version; use IMPL::clone qw(clone); use Scalar::Util qw(blessed); +use POSIX; use Carp qw(carp); -our @EXPORT = qw(&is &isclass &typeof); +our @EXPORT = qw(&is &isclass &typeof &coarsen); our %EXPORT_TAGS = ( base => [ qw( @@ -134,6 +135,11 @@ $class->static_accessor( $name, $value ); } +sub coarsen { + my ( $value, $resolution ) = @_; + return $resolution ? ceil( $value / $resolution ) * $resolution : $value; +} + sub equals { if (defined $_[0]) { return 0 if (not defined $_[1]);