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

  • Home
  • SEARCH
  • 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 9069009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:19:11+00:00 2026-06-16T17:19:11+00:00

I am now running the following assembly codes to get the cos function value:

  • 0

I am now running the following assembly codes to get the cos function value:

float cosx( float radians ) {
    float result;

    __asm__ __volatile__ ( "fld %1;"
                            "fcos;"
                            "fstp %0;"
                            : "=m" (result)
                            : "m" (radians)
    ) ;
    return result ;
}

However, the above function can accept float argument, and the obtained function value is also float type. I was therefore writing a similar function that can accept double argument, and the returned function value is supposed to reach double accuracy as well:

double cosx( double radians ) {
    double result;

    __asm__ __volatile__ ( "fld %1;"
                            "fcos;"
                            "fstp %0;"
                            : "=m" (result)
                            : "m" (radians)
    ) ;
    return result ;
}

However, the second function has been proved not to work properly. I am therefore wondering what I should do in oder to make the second function work well. Thanks! I am using gcc for compiling the above codes.

EDIT:
Here I will show why the second function does not work well:

int main() {
    float theta ;
    printf( "Enter theta  : " ) ;
    scanf( "%f", &theta ) ;  
     printf( "cosx(%f) = %lf\n", theta, cosx(theta) );  // line 5
     printf( "cosx(%f) = %lf\n", theta, cosx(double(theta)) ); // line 6

    return 0 ;
}

As we can see line5 and line6 invoke the first and the second function respectively. We expect they can have the same value. However, the output of the demonstration program is as follows:

Enter theta in  :  0.5236 // pi/6
cos(0.5236) = 0.8660;
cos(0.5236) = 0.0000;
  • 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-06-16T17:19:12+00:00Added an answer on June 16, 2026 at 5:19 pm

    GCC is picky about the operand types:

    __asm__ __volatile__ ( "fld %1;"
                            "fcos;"
                            "fstp %0;"
                            : "=m" (result)
                            : "m" (radians)
    

    Should be:

    __asm__ __volatile__ ( "fldl %1;"
                            "fcos;"
                            "fstpl %0;"
                            : "=m" (result)
                            : "m" (radians)
    

    Though you could also write it as:

    __asm__ __volatile__ ( "fldl %1;"
                          "fcos;"
                          : "=t" (result)
                          : "m" (radians)
                          ) ;
    

    (and the same for the float version)

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

Sidebar

Related Questions

I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
Running the following code: import os import datetime import ftplib currdate = datetime.datetime.now() formatdate
I am right now running a bash script in which i need to change
I recently updated my Eclipse (now running 20100218-1602), and I've found whenever I click
My program is now still running to import data from a log file into
I have a website running now. I have to implement some logging routines as
I have a python process running now , but it hangs with no log、no
I now have a running Java program which only lacks of the final step,that
I have a coldfusion application running right now with a login that sends a
I have an asp.net website in my production server which running fine now. Now

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.