Questions tagged [casting]
Casting is a process where an object type is explicitly converted into another type if the conversion is allowed. This process might lead to a change in value.
18,916
questions
0
votes
0
answers
4
views
java.lang.Class cannot be cast to clojure.lang.IFn when date capturing and string formatting
I'm not really seeing where I'm going wrong here, especially since I hit upon a minor variation at one point that allowed this, but couldn't explain why it worked. Please also tell me, in a more ...
0
votes
1
answer
24
views
How to tf.cast a field within a tensorflow Dataset
I have a tf.data.Dataset that looks like this:
<BatchDataset shapes: ((None, 256, 256, 3), (None,)), types: (tf.float32, tf.int32)>
The 2nd element (1st if zero indexing) corresponds with a ...
0
votes
1
answer
24
views
How to safe-cast a null into a generic type <T>?
I want to know if there's a way to make a safe cast from null, the next example throws an UNCHECKED CAST warning:
fun <T> notInitialized(): T = null as T
So, If anyone has an idea of how to ...
0
votes
0
answers
8
views
React Query UseQueryResult type narrowing
I'm using a list of queries with react-query to fetch "dependencies" and I want all the dependencies to load before rendering my component. I get the success state by checking all the deps ...
2
votes
0
answers
25
views
Why does array cast Int32[] to UInt32[] work only after conversion through Object? [duplicate]
It's obvious that UInt32 can not accurately represent Int32 values, but what's the mechanism behind the following chain conversion allowing to perform cast?
Int32[] a = { 1, 20, 0, 5, 7, 9};
...
-1
votes
0
answers
15
views
Slow downcast of pandas dataframe to np.float16
I have 1.05GB panda dataframe which is read into memory in about 20 seconds, but when I downcast numerical columns to np.float16 it takes more than 8 minutes:
print(datetime.now(), "reading ...
0
votes
0
answers
5
views
Reason: liquibase.exception.DatabaseException: ERROR: must be owner of type character varying or type json
DO '
BEGIN
CREATE CAST (varchar AS JSON) WITH INOUT AS ASSIGNMENT;
EXCEPTION
WHEN duplicate_object THEN null;
END '
;
I have this in my init.sql file.. it runs fine in my local postgres pdadmin.. but ...
0
votes
0
answers
15
views
How to cast Moq object to check type for dependency injection
I have created a wrapper class for the Microsoft DependencyInjection to simplify some of the calls in my application. I am trying to write unit tests that use Moq to insert objects into the dependency ...
0
votes
1
answer
56
views
Can Some one explain why I get these output?
I am new to c.
My Question.
Why do some numbers end up negative when the value was positive? Why do some
small numbers end up with a huge magnitude when typecast to unsigned?
#include <stdio.h>...
0
votes
1
answer
58
views
Issue with C++ type casting
I am trying to typecast a float to unsigned char using the following C++ code:
#include <iostream>
int main()
{
std::cout << int((unsigned char)((float)-10)) << "\n&...
1
vote
0
answers
32
views
no match for 'operator+' in basic_string <char> and uchar
I'm trying to create a concatenated string using a basic_string<char> and a uchar* (unsigned char*). I'm running into issues and have tried every method possible.
My code looks like this at the ...
0
votes
0
answers
6
views
Casting a MM:SS string into a double
My first stackoverflow question!
I am sure this answer must be buried somewhere in here, but I was unable to find it after about 90 mins of searching (gotta up my search game, for sure).
Anyways, I ...
0
votes
0
answers
20
views
Typescript - Cast string to custom complex object
I have this string returned by an automated system.
"[
{
key: "FACTORY",
prefix: () => h(NButton, { text: true, type: "primary" }, { default: () => ...
0
votes
1
answer
150
views
Is this casting and std::launder C++ standard conform and no undefined behavior
first a word in advance: The following code should not be used as it is and is just the condense of working code to the critical point. The question is only where does the following code violate the ...
0
votes
1
answer
53
views
Runtime error when casting from FARPROC to function pointer with varargs
I'm working on an old program that doesn't save or load its files anymore. While looking around in a DLL for a place to start, I noticed that there is some logging functionality that is disabled by ...
0
votes
2
answers
24
views
How a value can be of type integer, double & num at the same time?
I have the following expression:
const value = 10 / 2;
In VS Code, if I hover over value, it shows me its type is double, which makes sense. But if I run the following lines of code, they all ...
1
vote
2
answers
41
views
className SerialNow = *((className*)ptr); vs className &SerialNow = *((className*)ptr);
What is difference beween using or not reference when casting pointer to object?
void someClass::method(){
xTaskCreatePinnedToCore(someTaskHandler,"SerialNowTaskTX",XT_STACK_MIN_SIZE*3,...
0
votes
2
answers
38
views
Is it possible to define a custom cast on an object to become the result of a method call?
Is it possible to define a custom cast on an object so that the objects casts to the result of a method call?
class Foo {
public:
...
int method() { return 3; }
};
Foo foo;
int bar = foo + ...
-1
votes
1
answer
41
views
Global pointers in c
I want to know how I am getting answer for
the below code can anyone pls explain ..
In c language..
#include <stdio.h>
int*p;
void fun(int a, int b)
{
int c;
c = a+b ;
p=&c;
}
...
0
votes
0
answers
13
views
Cannot cast List<dynamic> to List<String> when it clearly is the case [duplicate]
I'm loading some data in my flutter app from storage, stored in JSON format, using jsonDecode. The stored format, stored using jsonEncode, is Map<String, List<String>>.
I can retrieve the ...
0
votes
2
answers
38
views
Fixing "incompatible types: possible lossy conversion from int to byte" in Java
I have question regarding my code here:
public class Main
{
public static void main(String[] args) {
System.out.println("Hello World\n");
int x = 36;
...
0
votes
1
answer
14
views
How do I cast an output of my IF function in BigQuery
How do I change Small_Bag_Percent as Numeric upto 2 decimals?
Here is the query:
SELECT
Total_Bags,
Small_Bags,
Large_Bags,
XLarge_Bags,
Small_Bags+Large_Bags+XLarge_Bags AS Total_Bags_Calc,
...
0
votes
1
answer
23
views
Summation of 2 floating point values gives incorrect result with higher precision
The sum of 2 floating values in postgres gives the result with higher precision.
Expected:
669.05 + 1.64 = 670.69
Actual:
SELECT CAST(669.05 AS FLOAT) + CAST(1.64 AS FLOAT)
------------------
670....
1
vote
1
answer
26
views
Casting structs to add definition to a shared-memory block in a SIMD application
I am building an application that requires the use of a large block of shared memory space of type double. This block needs to be byte aligned to ensure proper loading into SIMD registers. For example
...
0
votes
0
answers
42
views
How fetch value DateTime format from SQL Server database in ASP.NET
I have this ASP.NET code that fetches all data from a SQL Server database table:
connection.Open();
using (SqlCommand command = new SqlCommand(@"SELECT top 10 [Raspberry_ID],[Raspberry_name],[...
0
votes
1
answer
24
views
Using Pandas: function matches column name, unable to perform function [duplicate]
I was given a table by a client named with a column named "rank", and I'm trying to convert the values in that column to an int type, but when I try to run the df.rank.astype(int) function ...
3
votes
1
answer
83
views
Why is the return value type of std::round not an integer?
I had/have some confusion regarding rounding a float/double variable to the nearest integer. While googling, I came across this cppreference page for rounding. On that page, it says:
float round ...
0
votes
2
answers
38
views
TypeScript: Generic function which returns the same type as parameter
Consider this (which doesn't compile):
function roundTo<T = number | null | undefined>(
num: T,
decimals: number,
): T {
if (num === null || num === undefined) return num;
const factor =...
0
votes
0
answers
51
views
Function-based index on object type
I have a column in an Oracle 18c table that is an object type (user-defined type): Esri's ST_GEOMETRY spatial type.
I want to create a function-based index on that column:
create or replace function ...
0
votes
1
answer
34
views
At what point does a Carbon object turn to string in Laravel?
Looking to write a cast similar to Carbon dates with Laravel, I realized that a Carbon date is converted to a string when passed over to the front-end or blade component.
I have been digging the ...
0
votes
0
answers
43
views
Is slicing and casting the same in C++? [duplicate]
In C++ is slicing and casting the same? Or are there some differences? I am studying for a C++ and Object-Oriented Design exam and in the course notes I am reading they use both words but I do not ...
0
votes
2
answers
49
views
Don't know how to create ISeq from: Java.lang.Long
Doing some practice on recursion and map implementation to knock some rust off Clojure. I'm using lists only here so how am I trying to mix seq and non-seqable stuff?
(defn mapset
([operator operand]...
1
vote
1
answer
25
views
casting of js.executeAsyncScript output to Map<String,String>
I want to cast the output of below script into Map<string,string> but it is showing "java.lang.String cannot be cast to java.util.Map"error.
How can we cast that in map??
final ...
0
votes
0
answers
20
views
Audio not working when casting YouTube embedded in Google Slide
Issue is as follows:
ChromeOS v98 onwards (maybe earlier)
In Google Slides, insert a YouTube video. Cast to a screen, audio only plays on the chromebook not the tv you are casting to
Windows laptop ...
0
votes
1
answer
11
views
PostgreSQL - how can I Add separators to an undelimited date column?
I have a date column that is of a string format. The dates appear like,
DDMMYYY or DDMYYYY
04032021 0412021
It has been a nightmare trying to split them and add '-' because they aren't all the same ...
0
votes
1
answer
43
views
Scss how convert string to numeric value
I want to perform mathematical operations using the font-size information with the function below. I remove the rem unit information of $font-size using the sass build-in string functions, but then I ...
2
votes
1
answer
88
views
Casting an object to its class
I am trying to create some classes with two variables. One of the variables is Name the other one is Value. For each class value can be different type of variables (int , double or string).
I want to ...
1
vote
1
answer
60
views
qsort() results in segmentation fault
I've been tasked with implementing a type safe dynamic vector structure in C; however, I seem to have a problem: Every time I use the qsort() and then try casting the variables to an int* (in both ...
0
votes
1
answer
40
views
Java ClassCastException confusion
I have the following code:
PriorityQueue<Pair<Integer, Double>> pq =
new PriorityQueue<>((v1, v2) -> (int)Math.floor(v1.getValue() - v2.getValue()));
pq.add(new Pair(1, 0));...
0
votes
0
answers
29
views
Dbeaver SQL Cast Convert
I am a beginner of SQL and I am using Dbeaver.
I connected Excel csv data to my Dbeaver working space and all the date format is string
So to do some work, I want some columns to be integer but cast ...
2
votes
1
answer
89
views
How to convert a `f64` to a `f32`?
How can I convert a f64 into the closest f32?
There is neither a From nor a TryFrom implementation, presumably because such implementations are only provided for lossless conversions. I also searched ...
0
votes
1
answer
30
views
Mock object cannot be cast to Entity object using ModelMapper in unit test
I am unit testing a service method create product. This method takes in a Dto object and then transfers the Dto object to a ProductEntity object using ModelMapper. This method works fine but when I ...
1
vote
0
answers
27
views
How to correctly define a dispatching function in C++?
I have the following problem:
I receive commands through an AF_UNIX socket (no problems about network byte ordering).
the first word in packet is the command, the remainder is "parameters".
...
0
votes
0
answers
14
views
Casting irresponsive
Tried to do casting on this little project I am working on can anyone tell me what I have done wrong?
Calculation_to_units = 24
name_of_unit = "hours"
def days_to_units(num_of_days):
...
0
votes
0
answers
13
views
Python-docx: convert type <class 'docx.oxml.text.run.CT_R'> to <class 'docx.text.run.Run'> to apply a highlight
I have a function using python-docx which outputs a CT_R object. I'd like to be able to convert it to a Run object such that I can then apply a styling change, something like:
font.highlight_color = ...
0
votes
0
answers
41
views
Powershell decimal to [Int] not failing
I am trying to validate a string of what should be comma separated integer values to use as success codes. If I start with an array with some invalid values, like this...
$test = @(0, 100, -200, 3.3, '...
-1
votes
2
answers
42
views
Arbitrary type conversion in python
An arbitrary typecasting function (shown below as cast) seems like a fairly straightforward function:
print(type(variable))
variable = cast(variable,type) # where type is any type included in ...
0
votes
0
answers
32
views
Postgres ERROR: cannot cast type double precision to date [duplicate]
I have a table with creation timestamps as decimals and am trying to convert to date data type. When I go to cast as date I get the following error message: "ERROR: cannot cast type double ...
0
votes
0
answers
10
views
Coverting RDD of list into RDD of Rows Pyspark
is it possible to convert a rdd of string lists into a rdd with the Row format?
I read the first rdd with the textFile function specifying the split condition
0
votes
1
answer
49
views
error: invalid cast from type ‘void (*)(int)’ {aka ‘void (*)(int)’} to type ‘void’
void* l = dlsym(lib,"_ZN11Environment9LibLogger14log_processingEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjS6_z");
void (*log_fcn)(int level, std::string format, unsigned int ...