# Does openFHE support comparison?

**URL:** <https://openfhe.discourse.group/t/does-openfhe-support-comparison/228>\
**Category:** Library Questions\
**Created:** [November 16, 2022, 11:23pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228 "2022-11-16T23:23:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mola](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@mola](https://openfhe.discourse.group/u/mola)\
**Post date:** [November 16, 2022, 11:23pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/1 "2022-11-16T23:23:38Z")

</div>

does openFHE support some function that can do the comparison of 2 encrypted numbers?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [November 17, 2022, 1:47am UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/2 "2022-11-17T01:47:05Z")

</div>

yes, see [openfhe-development/eval-sign.cpp at main · openfheorg/openfhe-development · GitHub](https://github.com/openfheorg/openfhe-development/blob/main/src/binfhe/examples/eval-sign.cpp) It is based on TFHE/FHEW. The algorithm is described/proposed in [Large-Precision Homomorphic Sign Evaluation using FHEW/TFHE Bootstrapping](https://eprint.iacr.org/2021/1337)

---

<div class="post-metadata">

**Author:** ![mola](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@mola](https://openfhe.discourse.group/u/mola)\
**Post date:** [November 17, 2022, 9:01am UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/3 "2022-11-17T09:01:32Z")

</div>

Thank you very much for replying! I run exact same code in eval-sign.cpp, but got some thing like: “openfhe-development/src/binfhe/lib/fhew.cpp:914 ERROR: EvalSign is only for large precision. For small precision, please use bootstrapping directly”. What does that means?

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [November 17, 2022, 10:20pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/4 "2022-11-17T22:20:22Z")

</div>

I just ran the example using the default settings, i.e., when \log Q=17, and it worked without any problems. Did you try to run it for a smaller \log Q? This would cause the exception to be thrown. In the current implementation Q needs to be larger than q.

As a side note, the case of Q=q (1 bootstrapping) requires a trickier API now, and we can make it simpler to use (i.e., we can add support for it directly to `EvalSign`). Is this the case you tried?

---

<div class="post-metadata">

**Author:** ![mola](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@mola](https://openfhe.discourse.group/u/mola)\
**Post date:** [November 18, 2022, 12:56pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/5 "2022-11-18T12:56:00Z")

</div>

hi, i didn’t change anything in the eval-sign.cpp, and i got:  
logQ: 17  
Q: 131072  
q: 4096  
factor: 32  
p: 512  
but i still got the error “EvalSign is only for large precision. For small precision, please use bootstrapping directly”. I run the code on MacBook with M2 chip, would that affect the result?

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [November 18, 2022, 3:03pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/6 "2022-11-18T15:03:33Z")

</div>

1. As a sanity check can you give us more details? E.g what macbook make, compiler, etc.?

2. Have you followed all the instructions listed out in our discord [Installing OpenFHE on MacOS](https://openfhe-development.readthedocs.io/en/latest/sphinx_rsts/intro/installation/macos.html#installing-openfhe-on-macos)

---

<div class="post-metadata">

**Author:** ![mola](https://avatars.discourse-cdn.com/v4/letter/m/7ea924/32.png) [@mola](https://openfhe.discourse.group/u/mola)\
**Post date:** [November 18, 2022, 4:13pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/7 "2022-11-18T16:13:59Z")

</div>

Thank you very much! I reinstall the whole thing and it worked!

---

<div class="post-metadata">

**Author:** ![iquah](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/iquah/32/8_2.png) [@iquah](https://openfhe.discourse.group/u/iquah)\
**Post date:** [November 18, 2022, 4:15pm UTC](https://openfhe.discourse.group/t/does-openfhe-support-comparison/228/8 "2022-11-18T16:15:20Z")

</div>

Amazing! Thank you and please mark this as solved since it osunds like we addressed all your questions 🙂
