# HG changeset patch # User cin # Date 1441578925 -10800 # Node ID 5c80e33f1218d7f560b0b7ae07b401e97ee3589c # Parent c6e90e02dd17e214210fcdf4ab996125abfe9cd6 added 'coarsen' function diff -r c6e90e02dd17 -r 5c80e33f1218 lib/IMPL/lang.pm --- 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]);