Spreadsheet::Engine::Function::EVEN - Spreadsheet funtion EVEN()


Spreadsheet-Engine documentation Contained in the Spreadsheet-Engine distribution.

Index


Code Index:

NAME

Top

Spreadsheet::Engine::Function::EVEN - Spreadsheet funtion EVEN()

SYNOPSIS

Top

  =EVEN(value)

DESCRIPTION

Top

This rounds the value to the nearest even integer, away from zero.

HISTORY

Top

This is a Modified Version of code extracted from SocialCalc::Functions in SocialCalc 1.1.0

COPYRIGHT

Top

LICENCE

Top

The contents of this file are subject to the Artistic License 2.0; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.perlfoundation.org/artistic_license_2_0


Spreadsheet-Engine documentation Contained in the Spreadsheet-Engine distribution.

package Spreadsheet::Engine::Function::EVEN;

use strict;
use warnings;

use base 'Spreadsheet::Engine::Fn::math';

sub calculate {
  my ($self, $value) = @_;
  my $result = $value < 0 ? -$value : $value;
  my $extra = $result - int($result);
  if ($extra) {
    $result = int($result + 1) + (($result + 1) % 2);
  } else {    # integer
    $result = $result + ($result % 2);
  }
  $result = -$result if $value < 0;
  return $result;
}

1;

__END__