Welcome to the Parallax Discussion Forums, sign-up to participate.

# Multiply Longs

Posts: 224
edited 2018-08-01 - 11:23:44
```deg30 := speedtix ** \$1555_5555                              ' speedtix / 360 * 30
```

I have looked in the help files and on the internet on how to implement this Spin example in C, and there are so many conflicting answers I can't make sense of them.

The Propeller is like cool and stuff..... uhhh.....huh huh.

• Posts: 2,991
If you're ever stuck trying to convert some Spin code to C, try using spin2cpp. For example,
```pub mulx(speedtix) : deg30
deg30 := speedtix ** \$1555_5555
```
is converted by spin2cpp into:
```#define Highmult__(X, Y) ( ( (X) * (int64_t)(Y) ) >> 32 )
int32_t foo::mulx(int32_t speedtix)
{
int32_t deg30 = 0;
deg30 = Highmult__(speedtix, 357913941);
return deg30;
}
```

This simplifies manually to:
```deg30 = (speedtix * (int64_t)0x15555555) >> 32;
```
• Posts: 224
Thats pretty cool.
Thankyou
The Propeller is like cool and stuff..... uhhh.....huh huh.
• Posts: 2,211
Or just like that:
```deg30 = speedtix / 12;                              // speedtix / 360 * 30
```
• Posts: 22,284
Isn't the assignment in this line redundant?
```  int32_t deg30 = 0;
```

I mean, why set the variable to zero, when you're only going to change it in the next line?

-Phil
Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
• Posts: 2,991
Isn't the assignment in this line redundant?
```  int32_t deg30 = 0;
```

I mean, why set the variable to zero, when you're only going to change it in the next line?

Yes, it's redundant in this case. In some other cases (e.g. if the assignment below were conditional) then it would be necessary. spin2cpp is an automatic tool, so sometimes it outputs code that isn't as tidy as a human would write. The C compiler will optimize away the redundant assignment, so I didn't put any particular effort into preventing it.