~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to erts/emulator/beam/erl_arith.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ``The contents of this file are subject to the Erlang Public License,
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 * 
 
4
 * Copyright Ericsson AB 1999-2009. All Rights Reserved.
 
5
 * 
 
6
 * The contents of this file are subject to the Erlang Public License,
2
7
 * Version 1.1, (the "License"); you may not use this file except in
3
8
 * compliance with the License. You should have received a copy of the
4
9
 * Erlang Public License along with this software. If not, it can be
5
 
 * retrieved via the world wide web at http://www.erlang.org/.
 
10
 * retrieved online at http://www.erlang.org/.
6
11
 * 
7
12
 * Software distributed under the License is distributed on an "AS IS"
8
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
14
 * the License for the specific language governing rights and limitations
10
15
 * under the License.
11
16
 * 
12
 
 * The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
 
 * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
 
 * AB. All Rights Reserved.''
15
 
 * 
16
 
 *     $Id$
 
17
 * %CopyrightEnd%
17
18
 */
18
19
 
19
20
/*
185
186
                }
186
187
                goto big_shift;
187
188
            }
 
189
        } else if (is_big(arg2)) {
 
190
            /*
 
191
             * N bsr NegativeBigNum == N bsl MAX_SMALL
 
192
             * N bsr PositiveBigNum == N bsl MIN_SMALL
 
193
             */
 
194
            arg2 = make_small(bignum_header_is_neg(*big_val(arg2)) ?
 
195
                              MAX_SMALL : MIN_SMALL);
 
196
            goto do_bsl;
188
197
        }
189
198
    } else {
 
199
    do_bsl:
190
200
        if (is_small(arg2)) {
191
201
            i = signed_val(arg2);
192
202
 
223
233
                    else
224
234
                        ires -= (-i / D_EXP);
225
235
                }
 
236
 
 
237
                /*
 
238
                 * Slightly conservative check the size to avoid
 
239
                 * allocating huge amounts of memory for bignums that 
 
240
                 * clearly would overflow the arity in the header
 
241
                 * word.
 
242
                 */
 
243
                if (ires-8 > BIG_ARITY_MAX) {
 
244
                    BIF_ERROR(p, SYSTEM_LIMIT);
 
245
                }
226
246
                need = BIG_NEED_SIZE(ires+1);
227
247
                bigp = HAlloc(p, need);
228
248
                arg1 = big_lshift(arg1, i, bigp);
229
249
                maybe_shrink(p, bigp, arg1, need);
230
250
                if (is_nil(arg1)) {
 
251
                    /*
 
252
                     * This result must have been only slight larger
 
253
                     * than allowed since it wasn't caught by the
 
254
                     * previous test.
 
255
                     */
231
256
                    BIF_ERROR(p, SYSTEM_LIMIT);
232
257
                }
233
258
                BIF_RET(arg1);
237
262
                }
238
263
                goto big_shift;
239
264
            }
 
265
        } else if (is_big(arg2)) {
 
266
            if (bignum_header_is_neg(*big_val(arg2))) {
 
267
                /*
 
268
                 * N bsl NegativeBigNum is either 0 or -1, depending on
 
269
                 * the sign of N. Since we don't believe this case
 
270
                 * is common, do the calculation with the minimum
 
271
                 * amount of code.
 
272
                 */
 
273
                arg2 = make_small(MIN_SMALL);
 
274
                goto do_bsl;
 
275
            } else if (is_small(arg1) || is_big(arg1)) {
 
276
                /*
 
277
                 * N bsl PositiveBigNum is too large to represent.
 
278
                 */
 
279
                BIF_ERROR(p, SYSTEM_LIMIT);
 
280
            }
 
281
             /* Fall through if the left argument is not an integer. */
240
282
        }
241
283
    }
242
284
    BIF_ERROR(p, BADARITH);