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 4574004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:51:49+00:00 2026-05-21T19:51:49+00:00

I want to use the GSL for integration http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html However, I find no convenient

  • 0

I want to use the GSL for integration
http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html
However, I find no convenient way how the integrated function

(the function f in the example http://www.gnu.org/software/gsl/manual/html_node/Numerical-integration-examples.html)

can report an error to the integrator. I want to integrate a function which itself results from an integration that could fail. This is my sample program

#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>

double f (double x, void * params) {
    GSL_ERROR("test error",GSL_FAILURE);
    return 0.0;
}



int main (void)
{
gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);

double result, error;

gsl_function F;
F.function = &f;

gsl_set_error_handler_off();
int status = gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
                     w, &result, &error); 

printf ("status          = %d\n", status);
status  = GSL_FAILURE;
printf ("status          = %d\n", status);


gsl_integration_workspace_free (w);

return 0;
}

resulting in the output
status = 0
status = -1

I think the integrator should rather stop and return my error code. How can I achieve this?

Thank you very much for your help!!!

2011-04-27: I also tried this variant, after Brian Gough told me,

#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>

double f (double x, void * params) {
    GSL_ERROR("test error",GSL_FAILURE);
    return GSL_NAN;
}



int main (void)
{
gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);

double result, error;

gsl_function F;
F.function = &f;

gsl_set_error_handler_off();
int status = gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
                     w, &result, &error); 

printf ("status          = %d\n", status);
status  = GSL_FAILURE;
printf ("status          = %d\n", status);


gsl_integration_workspace_free (w);

return 0;
}

it did not help either. I will now fill out a bug report.

  • 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-21T19:51:50+00:00Added an answer on May 21, 2026 at 7:51 pm

    Thanks to Xuebin Wu from the GSL Mailing list the problem is solved:

    Hi,

    GSL_ERROR itself is a macro, it looks like

          gsl_error (reason, __FILE__, __LINE__, gsl_errno);
          return gsl_errno;
    

    The function already returns before you return NAN, because GSL_ERROR
    has been called. Turning the handler off just let the first line do
    nothing. The default error handler abort the program after printing
    error message.

    I do not think it is a bug. Maybe you can write your own error handler
    to solve your problem. For example, you can use “goto” to jump out of
    gsl_integration_qags, or set some global variable to indicate the
    integration result is incorrect.

    PS: I believe this macro is what you need,

    Macro: GSL_ERROR_VAL (reason, gsl_errno, value)
    This macro is the same as GSL_ERROR but returns a user-defined value
    of value instead of an error code. It can be used for mathematical
    functions that return a floating point value.

    The following example shows how to return a NaN at a mathematical
    singularity using the GSL_ERROR_VAL macro,

     if (x == 0)
       {
         GSL_ERROR_VAL("argument lies on singularity",
                       GSL_ERANGE, GSL_NAN);
       }
    

    So I adjusted the code according to

    #include <stdio.h>
    #include <math.h>
    #include <gsl/gsl_integration.h>
    #include <gsl/gsl_errno.h>
    
    double f (double x, void * params) {
    //  return GSL_NAN;
        GSL_ERROR_VAL ("argument lies on singularity", GSL_ERANGE, GSL_NAN);
    }
    
    
    
    int main (void)
    {
    gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
    
    double result, error;
    
    gsl_function F;
    F.function = &f;
    
    gsl_set_error_handler_off();
    int status = gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
                         w, &result, &error); 
    
    printf ("status          = %d\n", status);
    status  = GSL_FAILURE;
    printf ("status          = %d\n", status);
    
    
    gsl_integration_workspace_free (w);
    
    return 0;
    }
    

    and everything works as expected…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I just want to use the gsl_histogram.h library from Gnu Scientific Library (GSL),
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
So I want use Leaks to find the leaks in my app. In Xcode,
I need to use HTML comments to store specific data, but I don't want
I want use A-Z buttons on a html page like shown below (only sample
I Want Implement a Software by C#.net.I want Use a DataBase Manager Software like
How to do numerical integration (what numerical method, and what tricks to use) for
I want use groovy findAll with my param to filtering closure filterClosure = {
i want use some data from a website with web service. i have a
I have a transaction log file in CSV format that I want use to

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.