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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:41:19+00:00 2026-05-14T15:41:19+00:00

I’m compiling my code via the following command: icc -ltbb test.cxx -o test Then

  • 0

I’m compiling my code via the following command:

icc -ltbb test.cxx -o test

Then when I run the program:

time ./mp6 100 > output.modified
Floating exception
4.871u 0.405s 0:05.28 99.8%     0+0k 0+0io 0pf+0w

I get a “Floating exception”. This following is code in C++ that I had before the exception and after:

// before
if (j < E[i]) {
   temp += foo(0, trr[i], ex[i+j*N]);
}

// after
temp += (j < E[i])*foo(0, trr[i], ex[i+j*N]);

This is boolean algebra… so (j < E[i]) is either going to be a 0 or a 1 so the multiplication would result either in 0 or the foo() result. I don’t see why this would cause a floating exception.
This is what foo() does:

int foo(int s, int t, int e) {
    switch(s % 4) {
        case 0:
            return abs(t - e)/e;
        case 1:
            return (t == e) ? 0 : 1;
        case 2:
            return (t < e) ? 5 : (t - e)/t;
        case 3:
            return abs(t - e)/t;
    }
    return 0;
}

foo() isn’t a function I wrote so I’m not too sure as to what it does… but I don’t think the problem is with the function foo(). Is there something about boolean algebra that I don’t understand or something that works differently in C++ than I know of? Any ideas why this causes an exception?

Thanks,
Hristo

  • 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-14T15:41:20+00:00Added an answer on May 14, 2026 at 3:41 pm

    You are almost certainly dividing by zero in foo.

    A simple program of

    int main()
    {
        int bad = 0;
        return 25/bad;
    }
    

    also prints

    Floating point exception

    on my system.

    So, you should check whether e is 0 when s % 4 is zero, or whether t is 0 when s % 4 is 2 or 3. Then return whatever value makes sense for your situation instead of trying to divide by zero.


    @hristo: C++ will still evaluate the right-hand-side of a multiplication even if the left-hand-side is zero. It doesn’t matter that the result should be zero; it matters that foo was called and evaluated and caused an error.

    Sample source:

    #include <iostream>
    int maybe_cause_exception(bool cause_it)
    {
        int divisor = cause_it ? 0 : 10;
        return 10 / divisor;
    }
    
    int main()
    {
        std::cout << "Do not raise exception: " << maybe_cause_exception(false) << std::endl;
    
        int x = 0;
    
        std::cout << "Before 'if' statement..." << std::endl;
    
        if(x)
        {
            std::cout << "Inside if: " << maybe_cause_exception(true) << std::endl;
        }
    
        std::cout << "Past 'if' statement." << std::endl;
    
        std::cout << "Cause exception: " << x * maybe_cause_exception(true) << std::endl;
    
        return 0;
    }
    

    Output:

    Do not raise exception: 1

    Before 'if' statement...

    Past 'if' statement.

    Floating point exception

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

Sidebar

Ask A Question

Stats

  • Questions 384k
  • Answers 384k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You haven't said which version you want, but an archive… May 14, 2026 at 11:17 pm
  • Editorial Team
    Editorial Team added an answer From what I can tell this is a bug in… May 14, 2026 at 11:17 pm
  • Editorial Team
    Editorial Team added an answer According to this MSDN page about the NetworkInterface.NetworkInterfaceType property, This… May 14, 2026 at 11:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.