Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 934383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:59:28+00:00 2026-05-15T20:59:28+00:00

I have a problem in which I need to be prepared to explore a

  • 0

I have a problem in which I need to be prepared to explore a larger range of numbers than an unsized long long can represent (the range being represented by 3^(n*n) ). I have been advised by this community to use GMP for multiple-precision numbers. Since I need to iterate through the range one number at a time, I need a way to increment my counter easily.

My impulse is to use “mpz_add_ui(my_counter, my_counter, 1UL);”, but I am worried that passing my counter as both the return argument and as an addend may cause the result to be corrupted. If the function changes the return operator while it calculates the answer, it may change the number in such a way that the answer will turn out wrong. It is unlikely that incrementing will cause any trouble, but what about adding two large mpz_t’s? Or multiplying, or even exponentiation? The documentation has nothing to either calm or confirm my concerns. I’ve tried looking at the source code, but the combination of macros, sparse comments, and leaping from one file to another has lead me to conclude I am not good enough a programmer yet to follow it.

To be safe, I have written a function that shows the format I am fairly certain will work, but I would much rather avoid it because I am certain it will slow my program down:

void mpz_increment(mpz_t) {  
    mpz_t temp;  
    mpz_init(temp);  
    mpz_add_ui(temp, a, 1UL);  
    mpz_set(a, temp);  
    mpz_clear(temp);  
}

So, my question is this. Is it safe to pass a multiple-precision type to a GMP arithmetic function as both the return argument and one of the operands, or will doing so result in corrupted results?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:59:28+00:00Added an answer on May 15, 2026 at 8:59 pm

    Yes, you can pass the same instance as a input and output parameter. This is stated explicitly in the “Variable Conventions” section of the documentation:

    GMP lets you use the same variable for
    both input and output in one call. For
    example, the main function for integer
    multiplication, mpz_mul, can be used
    to square x and put the result back in
    x with

     mpz_mul (x, x, x);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.