Questions tagged [coercion]

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

Coercion, type conversion and typecasting are different ways of, implicitly or explicitly, changing an entity of one data type into another.

398 questions
0
votes
2 answers

ruby coerce method not called as expected

My aim is to implement an addition operator for a mathematical vector. I need ability to add scalars, arrays to MyVector. Also i need the operation to be commutative so i can add numbers to MyVector, and MyVector to number. I followed the recipe…
Vineet
  • 150
  • 1
  • 7
0
votes
1 answer

As3 Flash - Coercion Failed Errors Passing Third Party Data Types Swf to Swf

I am making a game where each screen is loaded in as a separate swf. I am loading the swf using Greensock's LoaderMax, but I don't think that is what is causing the issue. After I load in the swf I can set properties of the child swf like String and…
Mc' Flips
  • 1,023
  • 2
  • 9
  • 9
0
votes
2 answers

Problems coercing factors into intergers

I am trying to convert a factor (tickets_other) in a data frame (p2) into an integer. Following the R help guide, as well as other advice from others, this code should work: as.numeric(levels(p2$tickets_other))[p2$tickets_other] The column does…
David Johnson
  • 439
  • 1
  • 3
  • 13
0
votes
2 answers

R dataframe factors

I want to droplevels a dataframe (please do not mark this question as duplicate :)). Given all the methods available only one works. What am I doing wrong? Example: > df = data.frame(x = (c("a","b","c")),y=c("d","e","f")) > class(df$x) [1]…
MasterJedi
  • 1,618
  • 1
  • 18
  • 17
0
votes
4 answers

Is this coercion? Why is R telling me these are the same data types?

In a dataframe, I want to be able to separate columns with numeric types from columns with strings/characters. Here is my…
Max
  • 837
  • 4
  • 11
  • 20
0
votes
1 answer

Javascript variable name coercion to string

I'm trying to update a database in mongo using a string variable passed in. However, Javascript automatically coerces the variable type, and makes a "type" key in the database instead of what the string type points to is (let's say "notify" for…
svoges
  • 9
  • 1
0
votes
1 answer

Coercing a character to a numeric in R

I'm a newbie to R and I've learnt that a character string like "12.5" can be coerced to a numeric using as.numeric() function, which gives me the following result. > as.numeric("12.5") [1] 12.5 But when I try following, the result doesn't contain…
Pavithra Gunasekara
  • 3,902
  • 8
  • 36
  • 46
0
votes
1 answer

Providing primitive casts in ActionScript 3

In languages like Java, C++ and etc there is the ability to provide, for example, a toInt() function to allow your code to be converted neatly by language features into a given primitive type. (In this example, an Int.) That is, if you had…
That Guy
  • 103
  • 1
  • 8
0
votes
1 answer

How do one cast a instance of subclass to its superclass?

So I have this superclass grid class, and a subclass of the grid class named GrassTile1, GrassTile2, etc... all of the instance of the subclasses are stored in an array. How am I suppose to convert the instance of subclass to its superclass…
Mc Kevin
  • 962
  • 10
  • 31
0
votes
5 answers

Coercing template class with operator T* when passing as T* argument of a function template

Assume I have a function template like this: template inline void doStuff(T* arr) { // stuff that needs to use sizeof(T) } Then in another .h filee I have a template class Foo that has: public: operator T*() const; Now, I realize that…
hsivonen
  • 7,908
  • 1
  • 30
  • 35
0
votes
1 answer

TypeError: Error #1034: Type Coercion failed: cannot convert Object to Array

i have a Problem with the understanding of Sending Objects,Variable or else from my Red5 Java Server Application to a AS3 Script. The Problem im Facing is that i wrote down the following code in Java: ((IServiceCapableConnection)…
Artur Rem
  • 209
  • 1
  • 4
  • 18
0
votes
1 answer

Rails calculate the difference between two datetimes in seconds and converting to integer

I am trying to set :total_time to the difference between 2 datetime items (:start_time and :end_time) in seconds. I can get the value that I want in the view by doing the following <%= (@result.end_time.minus_with_coercion(@result.start_time)).round…
old_no_7uk
  • 369
  • 5
  • 16
0
votes
1 answer

as.Date in for loop performing unexpectedly

Why does this (admittedly unorthodox) use of as.Date within a for loop produce unexpected results? I have the following date vector: df.1 <- c("30-Sep-12", "30-Nov-12", "30-Sep-12", "30-Nov-12", "30-Sep-12", "30-Nov-12", "30-Sep-12") Now of…
Hugh
  • 15,521
  • 12
  • 57
  • 100
0
votes
1 answer

Deadly Diamond of Death in Coq

I'm trying to create a rather straight-forward type hierarchy. Here's a minimal working example: Record R0 : Type := { R0_S :> Type }. Record R1 : Type := { R1_S : Type; op1 : R1_S -> R1_S }. Record R2 : Type := { R2_S : Type; op2…
mhelvens
  • 4,225
  • 4
  • 31
  • 55
0
votes
3 answers

Is there a better way to coerce an integer to a floating point in Ruby besides .round(1)?

Just what the question says in the title. I have a pair of integers, I want to convert it to a floating point so that I can do floating point math on it (to get a nice percentage). Right now my code looks like…
Jazzepi
  • 5,259
  • 11
  • 55
  • 81