in reply to Coping with decimals

What have you tried already?

While Perl is a programming language with many special features, it still has the feature set that you can expect from other programming languages. Even if you don't know how to express this in Perl syntax, you should still be able to come up with a set of instructions that does what you want.

For example, the following set of instructions does what you want and should be easily implemented in Perl:

  1. If the absolute of the number x is smaller than 1.0, return the number
  2. If the number x is larger than 1, return the phase of the number x-1
  3. If the number x is smaller than -1, return the phase of the number x+1

It's easy to convince yourself that this will always produce a solution.