`print Math.sin(Math.pi / scale)`

(scale is a Double)

I get errors like:

Cannot apply SLASH to Double.

Cannot find a definition for "pi" in "Math".

Do I need to do some sort of type casting or overloading that I'm overlooking?

Forums

5 posts
• Page **1** of **1**

Since Cobra member access starts with a lower case letter, it's "pI". Certainly "pi" should be accepted and I'll enhance this. Not sure about the other error. I'd have to see the rest of your code. This works for me:

To reduce the ugliness, you could say:

And use "pi" from then on.

`class X`

def main is shared

scale = 1.0f

print Math.sin(Math.pI / scale)

To reduce the ugliness, you could say:

`pi = Math.pI`

And use "pi" from then on.

- Charles
**Posts:**2513**Location:**Los Angeles, CA

I didn't think to try that capitalization.

Here is a sample of code that produces the SLASH error:

In my code, I can probably do the arithmetic in another type, but I need to cast it to Double to pass it to the trig methods. And it would require doing about twice as many type casts that way.

Here is a sample of code that produces the SLASH error:

`"""`

MathTest.cobra

"""

class MathTest

shared

var _c as Double

def main

_c = 35.12 to Double

d = 1.456 to Double

print _c / d

In my code, I can probably do the arithmetic in another type, but I need to cast it to Double to pass it to the trig methods. And it would require doing about twice as many type casts that way.

- dennis
**Posts:**21

Right, Cobra's primitive types for numbers are now:

Suffixes:

Also, you can put underscores in numbers like so: "i = 10_000_000". That's 10 million. Works for floats and decimals too.

- int, uint (default 32 bits)
- int8, int16, int32, int64, uint8, uint16, uint32, uint64
- decimal
- float

Suffixes:

- f for float. ex: 1.5f
- d for decimal, but this is optional as it's the default.
- for integers, cast to the type: 1 to int64

Also, you can put underscores in numbers like so: "i = 10_000_000". That's 10 million. Works for floats and decimals too.

- Charles
**Posts:**2513**Location:**Los Angeles, CA

5 posts
• Page **1** of **1**

Users browsing this forum: No registered users and 5 guests