Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
U

User 22775

@User 22775
About
Posts
2
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Passing by value and printing in function
    U User 22775

    Hello, I have an assignment I am working on, I am stuck at a beggining point. Below is the code I am working with. This is pretty much what the professor gave us to start with, all I am trying to do right now is pass some values to the subroutine and then print them in the subroutine to confirm the values passed. We have to pass by value. I can print the values in the main fine, but then I always get zeroes in the subroutine. I have a lot more to do in the assignment, but have been stuck here. Any help would be greatly appreciated. Thanks, Paul unsigned long adddouble(unsigned long x, unsigned long y) { printf("%ld %ld \n", x, y); return(x+y); /* no interest at this time */ } main() { double d1, d2, *dp; unsigned long *longp1,*longp2, s; scanf("%lf %lf", &d1, &d2); /* get two input real numbers */ printf("%lf %lf \n", d1, d2); longp1 = (unsigned long *) &d1; longp2 = (unsigned long *) &d2; s = adddouble(*longp1,*longp2); }

    C / C++ / MFC help

  • Adding two IEEE754 double numbers
    U User 22775

    :confused:Hello, I have an assignment to write a C function to add two IEEE754 double numbers based on an algorithm in my text book. The function adds two positive doubles via two unsigned long parameters and returns the result also in unsigned long format. My professor gave us the main program and an empty subroutine and I need to code the subroutine. All I am trying to do for now is print the values that are entered by the user, not do any calculations, just print them in the main and then once they get into the subroutine and I can't even get that. It's been a year and a half since I have done any c programming, but I did not expect to be stumped this quickly ... Here is the code. I commented the lines that I added, not much. I understand the values I get when I print the HEX, but I get all zeroes when I try to print the decimal values. Thanks for any help. #include unsigned long adddouble(unsigned long x, unsigned long y) { //I added all unsigned long result; result = x; //print values of x and y printf("In subroutine, x = %f and y = %f\n", x ,y); printf("In subroutine, return = %f\n", result); return result; } int main(int argc, char* argv[]) { double d1, d2; double *dp; unsigned long s; unsigned long *longp1, *longp2; //get two input real numbers scanf("%lf %lf", &d1, &d2); longp1 = (unsigned long*)&d1; longp2 = (unsigned long*)&d2; //I added - hex value of what longp1 and longp2 point to printf("In main longp1 = %08x, %08x \n", *longp1, *(longp1+1)); printf("In main longp2 = %08x, %08x \n", *longp2, *(longp2+1)); //I added - decimal value of what longp1 and longp2 point to printf("In main longp1 = %f \n", *longp1); printf("In main longp2 = %f \n", *longp2); s = adddouble(*longp1, *longp2); dp = (double*)&s; printf("%f + %f = %f\n", d1, d2, *dp); return 0; } PC

    C / C++ / MFC algorithms help learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups