Skip to main content
0 votes
2 answers
70 views

Why doesn't Comparer support 64-bit (long) delegate return type for lambda operations in C#?

I'm trying to create a priority queue in C# that consists of 64-bit (long) integers in DESCENDING order. Unfortunately, it looks like .NET doesn't support this? Here's the code that fails: ...
Kris Craig's user avatar
-1 votes
1 answer
48 views

Swift - mutate struct after downcast

This is the abstraction of my code: protocol MyProtocol { var value1: Int {get set} var value2: Int {get set} } struct MyStruct: MyProtocol { var value1: Int = 1 var value2: Int = 2 ...
MassMover's user avatar
  • 537
1 vote
1 answer
54 views

What is the difference between using (double) versus multiplying by 1.0 when type casting an integer to a double?

I was wondering what the difference is between converting an integer to a double using double versus multiplying the integer by 1.0 int a = 4 int b = 3 double c = 1.0 * a / b double d = (double) a / ...
NoxAtra's user avatar
  • 13
1 vote
1 answer
64 views

How to downcast a trait to struct in Rust

I have the following trait defined: pub trait TItem { // some functions } I have two structs TArray and TObject with: impl TItem for TArray { // some functions } impl TItem for TObject { // ...
Andrew's user avatar
  • 319
0 votes
1 answer
35 views

Exception mapping string column value in Entity Framework Core 8 to an enum

I have an entity model which has a property of an enum type, and the values from the database column are strings. I get this exception when reading data from DbContext: Requested value 'PointSync' ...
Ed Hadipour's user avatar
1 vote
1 answer
59 views

How to safely cast integer in zig

The @intCast() causes undefined behavior when the target type cannot hold the resulting value. Is there something like @safeIntCast() or a similar function which would return CastError!anytype?
Verfin's user avatar
  • 25
0 votes
1 answer
105 views

How to assign values to a base struct that aren't reset when downcasted as shared pointers

In my program (attempt to make a programming language), I have tokens. The tokens are represented with structs. My issue is that I don't know how to "evolve" the base token into a more ...
galaxied's user avatar
0 votes
1 answer
40 views

Does PyTorch tensor type cast preserve information?

Consider the following simple operation, >>> t tensor([ 1.8750, -0.6875, -1.1250, -1.3750, 1.3750, -1.1250, 0.4688, -0.4062, 0.8750, -1.7500], dtype=torch.float) >>> t....
Sahil Gupta's user avatar
0 votes
1 answer
45 views

How do I cast an Eigen VectorXd value into a double?

My problem should be simple, but I have not been able to get it to work. I need to generate a random number from Eigen, set its range, and assign it t0 a double. It fails with all combinations I've ...
rsview's user avatar
  • 1
1 vote
1 answer
140 views

What's the best way to get the derived class from a base type pointer?

I tried two different ways to get a pointer to the derived class from a base pointer. One is: struct BaseClass { protected: int offset_of_derived; public: template <typename T> T* ...
Zebrafish's user avatar
  • 13.8k
0 votes
1 answer
76 views

Why does the conditional (ternary) operator (? :) in Java perform type casting? [duplicate]

I've been experimenting with the ternary operator (? :) in Java and noticed that it automatically performs type casting on its expressions. For example, this code returns 2.0 instead of 2: System.out....
vincentschulze's user avatar
0 votes
1 answer
37 views

Type 'string' is not assignable to type 'never'.ts(2322) const headerKey: never

I would like to ask why this particular line: rowData[headerKey] = value; is giving me this error: Type 'string' is not assignable to type 'never'.ts(2322) const headerKey: never Here is the code: ...
user19116203's user avatar
0 votes
2 answers
79 views

compiler complains that an unused variable is used when simply a cast to void is performed

We just found out that a certain compiler (Greenhills) sees the following construct as an error: // local variable mytype x; ... ((void) (x)); The compiler reports: error #549-D: variable "x&...
Sterpu Mihai's user avatar
0 votes
0 answers
41 views

Casting in C - confused [duplicate]

I have a tiny little code snipplet here: #include <stdio.h> #include <math.h> void main(void) { int clouds=15; double Zenith_rad=1.1827, Normal_direct=774.6839, A=0, B=0, C=...
Christian's user avatar
  • 317
0 votes
1 answer
57 views

User-defined implicit cast to generic is not used

I have a class that encapsulates a generic class T, and it has an implicit operator to convert the encapsulating class to T. However, that conversion is only ever used if I cast explicitly in the ...
Göran Roseen's user avatar

15 30 50 per page
1
2 3 4 5
1335