1 | n/a | /* |
---|
2 | n/a | * Copyright (c) 2008-2016 Stefan Krah. All rights reserved. |
---|
3 | n/a | * |
---|
4 | n/a | * Redistribution and use in source and binary forms, with or without |
---|
5 | n/a | * modification, are permitted provided that the following conditions |
---|
6 | n/a | * are met: |
---|
7 | n/a | * |
---|
8 | n/a | * 1. Redistributions of source code must retain the above copyright |
---|
9 | n/a | * notice, this list of conditions and the following disclaimer. |
---|
10 | n/a | * |
---|
11 | n/a | * 2. Redistributions in binary form must reproduce the above copyright |
---|
12 | n/a | * notice, this list of conditions and the following disclaimer in the |
---|
13 | n/a | * documentation and/or other materials provided with the distribution. |
---|
14 | n/a | * |
---|
15 | n/a | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND |
---|
16 | n/a | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | n/a | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | n/a | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
19 | n/a | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
20 | n/a | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
21 | n/a | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
22 | n/a | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
23 | n/a | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
24 | n/a | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
25 | n/a | * SUCH DAMAGE. |
---|
26 | n/a | */ |
---|
27 | n/a | |
---|
28 | n/a | |
---|
29 | n/a | #include "mpdecimal.h" |
---|
30 | n/a | #include <stdio.h> |
---|
31 | n/a | #include <stdlib.h> |
---|
32 | n/a | #include <assert.h> |
---|
33 | n/a | #include "bits.h" |
---|
34 | n/a | #include "difradix2.h" |
---|
35 | n/a | #include "numbertheory.h" |
---|
36 | n/a | #include "fnt.h" |
---|
37 | n/a | |
---|
38 | n/a | |
---|
39 | n/a | /* Bignum: Fast transform for medium-sized coefficients. */ |
---|
40 | n/a | |
---|
41 | n/a | |
---|
42 | n/a | /* forward transform, sign = -1 */ |
---|
43 | n/a | int |
---|
44 | n/a | std_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) |
---|
45 | n/a | { |
---|
46 | n/a | struct fnt_params *tparams; |
---|
47 | n/a | |
---|
48 | n/a | assert(ispower2(n)); |
---|
49 | n/a | assert(n >= 4); |
---|
50 | n/a | assert(n <= 3*MPD_MAXTRANSFORM_2N); |
---|
51 | n/a | |
---|
52 | n/a | if ((tparams = _mpd_init_fnt_params(n, -1, modnum)) == NULL) { |
---|
53 | n/a | return 0; |
---|
54 | n/a | } |
---|
55 | n/a | fnt_dif2(a, n, tparams); |
---|
56 | n/a | |
---|
57 | n/a | mpd_free(tparams); |
---|
58 | n/a | return 1; |
---|
59 | n/a | } |
---|
60 | n/a | |
---|
61 | n/a | /* reverse transform, sign = 1 */ |
---|
62 | n/a | int |
---|
63 | n/a | std_inv_fnt(mpd_uint_t *a, mpd_size_t n, int modnum) |
---|
64 | n/a | { |
---|
65 | n/a | struct fnt_params *tparams; |
---|
66 | n/a | |
---|
67 | n/a | assert(ispower2(n)); |
---|
68 | n/a | assert(n >= 4); |
---|
69 | n/a | assert(n <= 3*MPD_MAXTRANSFORM_2N); |
---|
70 | n/a | |
---|
71 | n/a | if ((tparams = _mpd_init_fnt_params(n, 1, modnum)) == NULL) { |
---|
72 | n/a | return 0; |
---|
73 | n/a | } |
---|
74 | n/a | fnt_dif2(a, n, tparams); |
---|
75 | n/a | |
---|
76 | n/a | mpd_free(tparams); |
---|
77 | n/a | return 1; |
---|
78 | n/a | } |
---|
79 | n/a | |
---|
80 | n/a | |
---|
81 | n/a | |
---|