|
[Date Index]
[Thread Index]
[Author Index]
Re: Putting a Test or Condition on the Right-Hand Side of a Function
- To: mathgroup at smc.vnet.net
- Subject: [mg127469] Re: Putting a Test or Condition on the Right-Hand Side of a Function
- From: Sébastien Roy <roys3d at gmail.com>
- Date: Fri, 27 Jul 2012 04:57:56 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <juqs5s$67q$1@smc.vnet.net>
Le jeudi 26 juillet 2012 03:38:36 UTC-4, Gregory Lypny a =E9crit :
> I have a simple function that displays the integer part of a real number if the fraction part is less than a millionth.
>
> dropDecimal[x_] := If[FractionalPart[x] < .000001, IntegerPart[x], x]
>
> In trying to learn more about functional programming, I was wondering whether there is a way to put the condition or test on the right-hand side of the
> function.
You could define it this way:
drop[x_] := IntegerPart[x] /; FractionalPart[x] < 0.000001;
drop[x_] := x;
The first definition applies only if the test is true. The second "more general" definition will apply if no "less general" definition is applicable.
Sebastien
Prev by Date:
How to relate two functions
Next by Date:
Heat Equation on a surface sphere using NDSolve?
Previous by thread:
Putting a Test or Condition on the Right-Hand Side of a Function
Next by thread:
Re: Putting a Test or Condition on the Right-Hand Side of a Function
|