| 4 | |
| 5 | === Errors about "float" === |
| 6 | |
| 7 | Symptoms include error messages you weren't expecting about method calls and "float" arguments: |
| 8 | {{{ |
| 9 | obj.foo(1.0, 1.0) # error: Cannot convert... |
| 10 | }}} |
| 11 | Cobra supports fractional values with the types: |
| 12 | * float32 |
| 13 | * float64 |
| 14 | * float (=float64) |
| 15 | * decimal (the default) |
| 16 | One of these types has to be the default type for values such as "1.0" and "x/y". Cobra uses "decimal" because it is more accurate with respect to the base-10 numbers people normally work with (e.g., 10%, 1.6). However, some libraries--especially for graphics and games--expect binary floating point numbers. If your application is oriented towards such numbers you can change the default number type by placing this in your code: |
| 17 | {{{ |
| 18 | @number float64 |
| 19 | }}} |
| 20 | Or passing it at the command line: |
| 21 | {{{ |
| 22 | cobra -number:float64 ... |
| 23 | }}} |
| 24 | You can also choose "float32". |
| 25 | |
| 26 | If you only need the occasional float, you can use suffixes like "_f64" and "_f32" (or "_d" for decimal): |
| 27 | {{{ |
| 28 | obj.foo(1.0_f32, 1.0_f32) |
| 29 | }}} |