Skip to content

Commit a761f12

Browse files
HarryRHarryR
authored andcommitted
Merge branch 'no-exceptional-control-flow' of github.com:Ethsnarks/libfqfft into no-exceptional-control-flow
2 parents 954e77d + c4f5457 commit a761f12

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

libfqfft/evaluation_domain/domains/basic_radix2_domain.tcc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ bool basic_radix2_domain<FieldT>::valid_for_size(const size_t m)
3535

3636
if (logm > FieldT::s)
3737
return false;
38-
39-
if (m != 1u << logm)
40-
return false;
4138
}
4239

40+
if( get_root_of_unity_will_throw<FieldT>(m) )
41+
return false;
42+
4343
return true;
4444
}
4545

libfqfft/evaluation_domain/domains/extended_radix2_domain.tcc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ bool extended_radix2_domain<FieldT>::valid_for_size(const size_t m)
3030

3131
if (logm != (FieldT::s + 1))
3232
return false;
33+
}
3334

34-
size_t small_m = m / 2;
35-
36-
if (small_m > FieldT::s)
37-
return false;
35+
size_t small_m = m / 2;
3836

39-
if (m != (1u << small_m))
40-
return false;
41-
}
37+
if( get_root_of_unity_will_throw<FieldT>(small_m) )
38+
return false;
4239

4340
return true;
4441
}

libfqfft/evaluation_domain/domains/step_radix2_domain.tcc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,13 @@ bool step_radix2_domain<FieldT>::valid_for_size(const size_t m)
2929
if (small_m != 1ul<<libff::log2(small_m))
3030
return false;
3131

32-
// Will `get_root_of_unity` throw?
33-
if (!std::is_same<FieldT, libff::Double>::value)
34-
{
35-
const size_t logm = libff::log2(m);
36-
37-
if (m != (1u << logm))
38-
return false;
32+
// omega
33+
if( get_root_of_unity_will_throw<FieldT>(1ul<<libff::log2(m)) )
34+
return false;
3935

40-
if (logm > FieldT::s)
41-
return false;
42-
}
36+
// small_omega
37+
if( get_root_of_unity_will_throw<FieldT>(1ul<<libff::log2(small_m)) )
38+
return false;
4339

4440
return true;
4541
}

libfqfft/evaluation_domain/evaluation_domain.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,34 @@
2727
#define EVALUATION_DOMAIN_HPP_
2828

2929
#include <vector>
30+
#include <libff/common/double.hpp>
3031

3132
namespace libfqfft {
3233

34+
template<typename FieldT>
35+
typename std::enable_if<std::is_same<FieldT, libff::Double>::value, bool>::type
36+
get_root_of_unity_will_throw(const size_t n)
37+
{
38+
return false;
39+
}
40+
41+
42+
template<typename FieldT>
43+
typename std::enable_if<!std::is_same<FieldT, libff::Double>::value, bool>::type
44+
get_root_of_unity_will_throw(const size_t n)
45+
{
46+
const size_t logn = libff::log2(n);
47+
48+
if (n != (1u << logn))
49+
return true;
50+
51+
if (logn > FieldT::s)
52+
return true;
53+
54+
return false;
55+
}
56+
57+
3358
/**
3459
* An evaluation domain.
3560
*/

0 commit comments

Comments
 (0)