Float+int math, c++ gcc

Discuss other programming languages besides AutoHotkey
User avatar
Spawnova
Posts: 302
Joined: 08 Jul 2015, 00:12
Contact:

Float+int math, c++ gcc

17 Jun 2017, 20:53

I'm trying to do int*float math, e.g. 5 * 0.5 //2.5 return as int, truncates to 2

However when I compile my c++ code and run it through ahk it returns nothing at all.

C++

Code: [Select all] [Download] GeSHi © Codebox Plus

int function(int value) {
float value2 = 0.5f;
return static_cast<int>(value * value2); //runs into a problem here and returns nothing
}


AHK

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I'm not sure if I'm doing something wrong, or if it's a compiler issue, was hoping someone could help me out with this.
Miguel7
Posts: 176
Joined: 08 Sep 2014, 07:06

Re: Float+int math, c++ gcc

13 Jul 2017, 13:28

Off-hand, my best guess would be that the float (0.5f) is being reduced to 0 when you cast it to an int. Anything * 0 = 0, so it would make sense that calling it wouldn't return anything.

On a separate note, what is the MCode? In the comment you said it's the compiled C++; does that mean it's some way to embed compiled C++ into AHK (cuz that would be awesome!)? :)

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 1 guest