casting

Operator '/' can't be applied to operands of types 'decimal' and 'double' - NCalc

↘锁芯ラ 提交于 2019-12-13 04:55:46
问题 I'm trying to run this formula in NCalc: "( Abs([a] - [b]) / ( ([a] + [b]) / 2.0 ) ) * 100" I get the error: Operator '/' can't be applied to operands of types 'decimal' and 'double' The [a] and [b] parameters are passed as Decimals. I tried putting 'm' on the 2 and 100 like so: "( Abs([a] - [b]) / ( ([a] + [b]) / 2m ) ) * 100m" But it throws an exception: Additional information: extraneous input 'm' expecting ')' at line 1:36 I followed this question, but it didn't help me. The same question

Split UInt32 (audio frame) into two SInt16s (left and right)?

我与影子孤独终老i 提交于 2019-12-13 04:44:23
问题 Total noob to anything lower-level than Java, diving into iPhone audio, and realing from all of the casting/pointers/raw memory access. I'm working with some example code wich reads a WAV file from disc and returns stereo samples as single UInt32 values. If I understand correctly, this is just a convenient way to return the 32 bits of memory required to create two 16 bit samples. Eventually this data gets written to a buffer, and an audio unit picks it up down the road. Even though the data

why casting Base object to derived type reference working?

99封情书 提交于 2019-12-13 04:38:52
问题 AFAIK, casting a base class object to derived type reference throws a run time exception.But in the below class, this works perfectly fine. public class Node<T> { // Private member-variables private T data; private NodeList<T> neighbors = null; public Node() {} public Node(T data) : this(data, null) {} public Node(T data, NodeList<T> neighbors) { this.data = data; this.neighbors = neighbors; } public T Value { get { return data; } set { data = value; } } protected NodeList<T> Neighbors { get

Check if Eval(“VALUE”) is null

倖福魔咒の 提交于 2019-12-13 04:35:54
问题 Quite new to C# I need to cast a value to add minutes to a date but it can be null. Here's how I do : if(Eval("DUREE") != DBNull.Value) { var duration = Convert.ToInt32(Eval("DUREE")); var date = Convert.ToDateTime(Eval("DATE")); var dateAsString = Convert.ToString(date.AddMinutes(duration)); DataBinder.Eval(Container.DataItem, dateAsString, "{0:HH:mm}") } else { " - " } Here the error I get : DataBinding : 'System.Data.DataRowView' doesn't comport properties called : '17/04/2014 13:30:00'.

Casting a const int to a pointer? [duplicate]

与世无争的帅哥 提交于 2019-12-13 04:34:24
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Modifying a const through a non-const pointer I have the following code: const int x = 5; int *p = (int*)&x; *p = 2; // Line 1 cout << x << " - " << *p << endl; cout << &x << " - " << p << endl; And got the results: 5 - 2 0012FF28 - 0012FF28 I know the code is weird and should never do it. But I wondered why the same address but got different result? And where the Line 1 store the number 2? 回答1: Because changing

Casting to a generic base type

寵の児 提交于 2019-12-13 04:27:38
问题 I have the following class structure: public class RelationBase : Entity { } public class RelationURL : RelationBase { } public class RelationBaseList<T> where T: RelationBase { public List<T> Collection { get; set; } } public class RelationURLList : RelationBaseList<RelationURL> { } public class RefTest { public RelationURLList urlList { get; set; } public RefTest() { urlList = new RelationURList(); urlList.Collection = new List<RelationUR>(); urlList.Collection.Add(new RelationUR()); } }

Why does this code compile with g++ but not gcc?

别来无恙 提交于 2019-12-13 04:25:48
问题 The following piece of code compiles with g++ and not gcc, and am stuck wondering why? inline unsigned FloatFlip(unsigned f) { unsigned mask = -int(f >> 31) | 0x80000000; return f ^ mask; } I would assume that in C++, int(f >> 31) is a constructor but that leaves me wondering why it's included in the code. Is it necessary? 回答1: C doesn't support the C++ "function-style" casting. You need to write it like this unsigned mask = -(int)(f >> 31) | 0x80000000; See cast operator 回答2: You can use C

What is the difference between a reinterpret_cast and a C-style cast? [duplicate]

放肆的年华 提交于 2019-12-13 04:24:49
问题 This question already has answers here : When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? (8 answers) Closed 5 years ago . What is the difference between : double x = 10.3; int y; y = (int) x; // c-like cast notation And : double x = 10.3; int y; y = reinterpret_cast<int>(x) 回答1: A C-style cast can be any of the following types of casts: const_cast static_cast static_cast followed by a const_cast reinterpret_cast reinterpret_cast followed by a const_cast the

Using an ArrayList<Class?> for casting?

自闭症网瘾萝莉.ら 提交于 2019-12-13 04:24:27
问题 Previous question I have the following code: ArrayList<Object> list = new ArrayList<Object>(); list.add("StringType"); list.add(5); list.add(new RandomClass()); List<Class<?>> classes = new ArrayList<>(); classes.add(String.class); classes.add(int.class); classes.add(RandomClass.class); for (int i = 0; i < list.size(); i++) { if (classes.get(i).isInstance(list.get(i))) { ... } } if (isvalid) mymethod(...); public void mymethod(String string, int num, RandomClass randomClass){ } Now I'm trying

How should I type cast void *?

亡梦爱人 提交于 2019-12-13 04:05:36
问题 I am learning C. I need to define a function to type cast the value of void * to the desired type. I'm not sure if I fully understand what I need to do. Here is my attempt. Can someone take a look and let me know if it's correct? If not, how should I fix it? Thank you in advance for your time. void print_type(TYPE a) { void *v_ptr; v_ptr = &a; } 回答1: In C, void * is implicitly compatible with any data pointer type. If you have a POSIX implementation, then it's compatible with function