~ubuntu-branches/ubuntu/trusty/pdl/trusty-proposed

« back to all changes in this revision

Viewing changes to Basic/Ops/ops.pd

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-12-05 12:37:41 UTC
  • mfrom: (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091205123741-ilqkc9s4zlk71z13
Tags: 1:2.4.5+dfsg-2ubuntu1
* Merge from debian testing (LP: #492898), remaining changes:
  - debian/perldl.conf: Enabled NAN support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
/* Note that this code causes some warning messages in the compile, because */
47
47
/* the unsigned data types always fail the ((foo)<0) tests.  I believe that */
48
48
/* gcc optimizes those tests away for those data types.  --CED 7-Aug-2002   */
 
49
/* Resurrect the old MOD operator as the unsigned US_MOD to get around this. --DAL 27-Jun-2008 */
49
50
 
50
51
#define MOD(X,N) (  ((N) == 0)   ?    0   :   (   (X) - (ABS(N))  *  ((int)((X)/(ABS(N))) + (   ( ((N) * ((int)((X)/(N)))) != (X) )   ?   ( ( ((N)<0) ? 1 : 0 )  +  ( (((X)<0) ? -1 : 0)))  :  0 ))))
51
52
 
 
53
#define BU_MOD(X,N) ( (X)-(N)*((int)((X)/(N))) )
52
54
#define SPACE(A,B)   ( ((A)<(B)) ? -1 : ((A)!=(B)) )
53
55
#define ABS(A)       ( (A)>=0 ? (A) : -(A) )
54
56
#define NOTHING
150
152
    # is this one to be used as a function or operator ?
151
153
    if ($isop) { $ovcall = "\$c = \$a $funcov \$b;    # overloaded use"; }
152
154
    else       { $ovcall = "\$c = $funcov \$a, \$b;    # overloaded use"; }
 
155
 
 
156
 
 
157
#a little dance to avoid the MOD macro warnings for byte & ushort datatypes
 
158
    my $codestr;
 
159
    my $badcodestr;
 
160
    if ($extra{unsigned}){
 
161
    $codestr = << "ENDCODE";
 
162
  types(BU) %{
 
163
  \$c() = BU_$func(\$a(),\$b());
 
164
  %}
 
165
  types(SLFD) %{
 
166
  \$c() = $func(\$a(),\$b());
 
167
  %}
 
168
ENDCODE
 
169
} else { 
 
170
   $codestr = "\$c() = $func(\$a(),\$b());";
 
171
   }
 
172
 delete $extra{unsigned}; #remove the key so it doesn't get added in pp_def.
 
173
 
 
174
 $badcodestr = 'if ( $ISBAD(a()) || $ISBAD(b()) )
 
175
               $SETBAD(c());
 
176
               else {' . $codestr . " } \n";
 
177
#end dance
 
178
 
153
179
    pp_def($name,
154
180
           HandleBad => 1,
155
181
           NoBadifNaN => 1,
156
182
           Pars => 'a(); b(); [o]c();',
157
183
           OtherPars => 'int swap',
158
184
           Inplace => [ 'a' ], # quick and dirty solution to get ->inplace do its job
159
 
           Code => 
160
 
           "\$c() = $func(\$a(),\$b());",
161
 
           BadCode =>
162
 
           'if ( $ISBAD(a()) || $ISBAD(b()) )
163
 
               $SETBAD(c());
164
 
            else' . "\n  \$c() = $func(\$a(),\$b());\n",
 
185
           Code => $codestr,
 
186
           BadCode => $badcodestr, 
165
187
           CopyBadStatusCode =>
166
188
           'if ( $BADFLAGCACHE() ) {
167
189
               if ( a == c && $ISPDLSTATEGOOD(a) ) {
291
313
# some standard binary functions
292
314
bifunc('power',['pow','op**'],1,'raise piddle C<$a> to the power C<b>',GenericTypes => [D]);
293
315
bifunc('atan2','atan2',1,'elementwise C<atan2> of two piddles',GenericTypes => [D]);
294
 
bifunc('modulo',['MOD','op%'],1,'elementwise C<modulo> operation');
295
 
bifunc('spaceship',['SPACE','op<=>'],1,'elementwise C<~> operation');
 
316
bifunc('modulo',['MOD','op%'],1,'elementwise C<modulo> operation',unsigned=>1);
 
317
bifunc('spaceship',['SPACE','op<=>'],1,'elementwise "<=>" operation');
296
318
 
297
319
# some standard unary functions
298
320
ufunc('sqrt','sqrt','elementwise square root', Exception => '$a() < 0' );