How do I resolve this argument error for RenderTarget2D? - arguments

I'm working with a bit of XNA code, as a beginner. So i use this tutorial, but it appears that i am doing something and i do not know why.
http://www.xnadevelopment.com/tutorials/theroadnottaken/theroadnottaken.shtml
I am at the part with Path collision, and this is how my code is written!
mTrackRender = new RenderTarget2D(graphics.GraphicsDevice, mCarWidth + 100,
mCarHeight + 100, 1, SurfaceFormat.Color,DepthFormat.Depth24);
mTrackRenderRotated = new RenderTarget2D(graphics.GraphicsDevice, mCarWidth + 100,
mCarHeight + 100, 1);
I have declared mTrackREnder, and mTrackREnderRotated has objects at class level.
Well, what the issue ism i get this error for both of them:
Error 3 'Microsoft.Xna.Framework.Graphics.RenderTarget2D' does not
contain a constructor that takes 4 arguments'
What am i doing wrong? How can i resolve this issue?

Take a look at the constructors of the RenderTarget2D class. None of them take the arguments that you are trying to pass.
In the first case, you are passing an integer where the constructor expects a boolean. Integers are not implicitely convertible to booleans in C#; use true and false instead of 1 and 0.
In the second case, it's not clear which constructor you are trying to call, but none of them take 4 arguments and none of them take an integer as the 4th argument.

Related

Is there a way to use range with Z3ints in z3py?

I'm relatively new to Z3 and experimenting with it in python. I've coded a program which returns the order in which different actions is performed, represented with a number. Z3 returns an integer representing the second the action starts.
Now I want to look at the model and see if there is an instance of time where nothing happens. To do this I made a list with only 0's and I want to change the index at the times where each action is being executed, to 1. For instance, if an action start at the 5th second and takes 8 seconds to be executed, the index 5 to 12 would be set to 1. Doing this with all the actions and then look for 0's in the list would hopefully give me the instances where nothing happens.
The problem is: I would like to write something like this for coding the problem
list_for_check = [0]*total_time
m = s.model()
for action in actions:
for index in range(m.evaluate(action.number) , m.evaluate(action.number) + action.time_it_takes):
list_for_check[index] = 1
But I get the error:
'IntNumRef' object cannot be interpreted as an integer
I've understood that Z3 isn't returning normal ints or bools in their models, but writing
if m.evaluate(action.boolean):
works, so I'm assuming the if is overwritten in a way, but this doesn't seem to be the case with range. So my question is: Is there a way to use range with Z3 ints? Or is there another way to do this?
The problem might also be that action.time_it_takes is an integer and adding a Z3int with a "normal" int doesn't work. (Done in the second part of the range).
I've also tried using int(m.evaluate(action.number)), but it doesn't work.
Thanks in advance :)
When you call evaluate it returns an IntNumRef, which is an internal z3 representation of an integer number inside z3. You need to call as_long() method of it to convert it to a Python number. Here's an example:
from z3 import *
s = Solver()
a = Int('a')
s.add(a > 4);
s.add(a < 7);
if s.check() == sat:
m = s.model()
print("a is %s" % m.evaluate(a))
print("Iterating from a to a+5:")
av = m.evaluate(a).as_long()
for index in range(av, av + 5):
print(index)
When I run this, I get:
a is 5
Iterating from a to a+5:
5
6
7
8
9
which is exactly what you're trying to achieve.
The method as_long() is defined here. Note that there are similar conversion functions from bit-vectors and rationals as well. You can search the z3py api using the interface at: https://z3prover.github.io/api/html/namespacez3py.html

The function "REVERSE" does not support the data type "DT_I4" for parameter number 1

i'm trying to make an expression for one of my variables in visual studio and I get this error saying:
The function "REVERSE" does not support the data type "DT_I4" for
parameter number 1. The type of the parameter could not be implicitly
cast into a compatible type for the function. To perform this
operation, the operand needs to be explicitly cast with a cast
operator.
Evaluating function "REVERSE" failed with error code 0xC0047089.
And this is my code:
SUBSTRING(#[User::FileName] , 1, REVERSE(FINDSTRING(#[User::FileName],"_", 1)))
Please help
Error message is pretty clear, you are doing a REVERSE of a FINDSTRING.
REVERSE's parameter needs to be literal values and FINDSTRING returns an integer (DT_I4).
I believe you want to do it the other way arround, first REVERSE the string and then calculate the position of the underscore, so that the SUBSTRING can take characters up to that point:
SUBSTRING(#[User::FileName] , 1, FINDSTRING(REVERSE(#[User::FileName]),"_", 1))
Edit: Try this to retrieve the last part after the last _.
SUBSTRING(
#[User::FileName],
LEN(#[User::FileName]) - FINDSTRING(REVERSE(#[User::FileName]),"_", 1) + 2,
LEN(#[User::FileName])
- (LEN(#[User::FileName]) - FINDSTRING(REVERSE(#[User::FileName]),"_", 1) + 2)
- FINDSTRING(REVERSE(#[User::FileName]),".", 1) + 1)

How to get precision (number of digits past decimal) from a Ruby BigDecimal object?

Given the following expression for a new BigDecimal object:
b = BigDecimal.new("3.3")
How can I get the precision that has been defined for it? I would like to know a method that will return 1, as there is 1 digit after the decimal. I'm asking this because b.precision or b.digits don't work.
Thanks to Stefan, a method name for dealing with such information is BigDecimal#precs. Given that a BigDecimal object comes from a database, I don't know the precision of that database object. I have tried the following, but it does not seem useful for my situation.
b = BigDecimal.new(3.14, 2)
b.precs
=> [18, 27]
How can I retrieve the 2 information/argument?
In Ruby 2.2.2 (and, I'm guessing, in prior versions), you can't get
back the precision that was given to BigDecimal::new. That's
because it is used in some computations; only the result of those
computations is stored. This doc comment is a clue:
The actual number of significant digits used in computation is
usually larger than the specified number.
Let's look at the source to see what's going on. BigDecimal_new
extracts the parameters, does some limit and type checking, and calls
VpAlloc. mf holds the digits argument to BigDecimal::new:
return VpAlloc(mf, RSTRING_PTR(iniValue));
In VpAlloc, mf gets
renamed to mx:
VpAlloc(size_t mx, const char *szVal)
The very first thing MxAlloc does is to round mx (the precision) up to
the nearest multiple of BASE_FIG:
mx = (mx + BASE_FIG - 1) / BASE_FIG; /* Determine allocation unit. */
if (mx == 0) ++mx;
BASE_FIG is equivalent to RMPD_COMPONENT_FIGURES, which has a platform
dependent value of either 38, 19, 9, 4, or 2.
There are further computations with mx before it is stored in the
BigDecimal being created, but we can already see that the original
argument passed to ::new is destroyed and not recoverable.

Requesting class constant value in Ruby returns all defined values within this class

Hello I've encountered one interesting piece of code on Ruby project I've just joined. I tried to google explanation what is causing behaviour that I'm experiencing, but without any luck.
I've got class definition like this
class Values
First = 1,
Second = 2,
Third = 3
end
At other place there is call for value like this Values::First
this returns
1
2
3
If I call Values::Second or Values::Third it correctly returns just single value.
Can someone explain why it happens when lines are ended with comma character?
Thank you for your answers.
First off, these are constants not class variables.
The commas mean that this is the same as
First = 1, Second = 2, Third = 3
Which is the same as
First = 1, (Second=2), (Third=3)
This sets Second and Third but is otherwise the same as
First = 1,2,3
Which sets First to the array [1,2,3]
Your syntax defines First as an Array, while also defining Second as 2 and Third as 3 in the process. Remove the commas to have First set to 1:
class Values
First = 1
Second = 2
Third = 3
end

Ada Enumerated Type Range

As I understand it, Ada uses 0 based indexes on its enumerated types.. So in Status_Type below, the ordinal value goes from 0 to 5.
type Status_Type is
(Undefined,
Available,
Fout,
Assigned,
Effected,
Cleared);
My question is.. what are the ordinal values for the following examples? Do they start at 0 or do they start from the ordinal value from the super type?
subtype Sub_Status_Type is Status_Type
range Available.. Effected;
subtype Un_Status_Type is Sub_Status_Type
range Fout .. Assigned;
Would Sub_Status_Type ordinal values go from 1 to 4 or from 0 to 3?
Would Un_Status_Type ordinal values go from 3 to 4 or from 1 to 2 or from 0 to 1?
For the subtypes, a 'pos will return the same value as it would have for the base type (1..4 and 2..3 respectively, I believe). Subtypes aren't really new and different types, so much as they are the same old type, but with some extra limitations on its possible values.
But it should be noted that these values are assigned under the scenes. It really should make no difference to you what they are, unless you are using the 'val and 'pos attributes, or you are interfacing to code written outside of Ada (or to hardware).
Plus, if it does end up mattering, you should know that the situation is actually much more complicated. 'pos and 'val don't return the actual bit value the compiler uses for those enumeration values when it generates code. They just return their "ordinal position"; their offset from the first value.
By default they will usually be the same thing. However, you can change the value assignments (but not the ordinal position assignments) yourself with a for ... use clause, like in the code below:
for Status_Type use
(Undefined => 1,
Available => 2,
Out => 4,
Assigned => 8,
Effected => 16,
Cleared => 32);
The position number is defined in terms of the base type. So Sub_Status_Type'Pos(Assigned) is the same as Status_Type'Pos(Assigned), and the position values of Sub_Status_Type go from 1 to 4, not 0 to 3.
(And note that the position number isn't affected by an enumeration representation clause; it always starts at 0 for the first value of the base type.)
Incidentally, it would have been easy enough to find out by running a small test program that prints the values of Sub_Status_Type'Pos(...) -- which would also have told you that you can't use the reserved word out as an identifier.
As I understand it, Ada uses 0 based indexes on its enumerated types
Yes, it uses 0 for the indexes, or rather for the position of the values of the type. This is not the value of the enumeration literals, and not the binary representation of them.
what are the ordinal values for the following examples?
There are no "ordinal" values. The values of the type are the ones you specified. You are confusing "value", "representation", and "position" here.
The values of your Status_Type are Undefined, Available, Out, Assigned, Effected, and Cleared.
The positions are 0, 1, 2, 3, 4, and 5. These are what you can use to translate with 'Pos and 'Val.
The representation defaults to the position, but you can freely assign other values (as long as you keep the correct order). These are used if you write it to a file, or send it through a socket, or load it into a register..
I think the best way to answer your questions is in reverse:
A subtype is, mathematically speaking, a continuous subset of its parent type. So, if the type SIZES is (1, 2, 3, 4, 5, 6, 7, 8) and you define a subtype MEDIUM as (4,5) the first element of MEDIUM is 4.
Example:
Type Small_Natural is 0..16;
Subtype Small_Positive is Small_Natural'Succ(Small_Natural'First)..Small_Natural'Last;
This defines two small sets of possible-values, which are tightly related: namely that Positive numbers are all the Natural Numbers save Zero.
I used this form to illustrate that with a few text-changes we have the following example:
Type Device is ( Not_Present, Power_Save, Read, Write );
Subtype Device_State is Device'Succ(Device'First)..Device'Last;
And here we are modeling the intuitive notion that a device must be present to have a state, but note that the values in the subtype ARE [exactly] the values in the type from which they are derived.
This answers your second question: Yes, an element of an enumeration would have the same value that its parent-type would.
As to the first, I believe the starting position is actually implementation defined (if not then I assume the LM defaults it to 0). You are, however free to override that and provide your own numbering, the only restriction being that elements earlier in the enumeration are valued less than the value that you are assigning currently [IIRC].

Resources