Hello guys, i'm trying to compute the area of a triangle using the Floating-Point stack (FPU87), but i'm having an issue outputting my value.

I'm computing the area using Heron's formula:
T = sqrt{s * (s - a ) * (s - b) * (s - c) }
Note: s = (a+b+c) / 2

I'm outputting: s * (s - a ) * (s - b) * (s - c), from the FPU87 stack just to make sure it did the calculations correctly, but i'm getting "-nan". I know it means "not a number", but as a test I inputted a = 1.0, b = 2.0, & c = 3.0 & by these calculations it should just output 0; s = (6)/2 = 3... (3)(3-1)(3-2)(3-3) = (3)(2)(1)(0) = 0.

I did all the calculations on the FPU87 stack then i'm outputting the number like so:

``````;Copy the number in st0 to memory.
mov qword rax, 0
push rax
push rax
fstp tword [rsp];Pop what's in st0 to int memory [s * (s - a ) * (s - b) * (s - c)]
fld tword [rsp]          ;Load the value back to FPU87 stack

;Ouput the "The area of the triangle is: " message
mov qword rdi, stringformat
mov qword rsi, thearea
mov qword rax, 0
call printf
;
;Output the extended area number
mov rdi, doubleoutputformat
mov qword rsi, [rsp]
mov qword rax, 0
call printf
;
pop rax
pop rax``````

The way i'm outputting the value is the same way I outputted a, b, & c after they were inputted, but for some reason after that whole calculation is done it outputs -nan.

Any help would be appreciated.
Thanks.

This is professor Holliday. This post has been logged and I am tracking your ip address.

This is the real Professor Holiday and I am tracking both your IP address.
I am filing an investigative report to track you bastards down.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.