|
I'm not sure if float will represent an entered 0 as all "bits" 0. It's the only time the value will be all zero bits. I can't remember if the exponent value is 0 or 1, but in either case, I think the exponent needs at least 1 bit to be set to 1.
In any case, the -0 concept has nothing to do with float types. It's for signed integers in a 1's comp environment. I'm not sure if 1's comp was still being produced 30 years ago, I do know I learned about it around 1979 and it was known then how poor that mathematical model was.
Basically -0 is produced by having all 1's set in a signed integer. You get it by first getting a negative number and then adding to reach 0. In 1's comp, every negative number is the exact complement of the same positive number. (Position to position every 1 bit is set to 0 and every 0 bit is set to 1 to change from a positive number to the same negative number.
In 1's comp, the 1's bit is on for odd positive numbers and off for odd negative numbers. In 2's comp the 1's bit is on for both positive and negative numbers.
|
|
|
|
|
-0 has everything to do with floats.
OK there is also one's complement, which died a long time ago. And sign-magnitude integers, which also died.
FYI, 0.0f = 0x00000000 and -0.0f = 0x80000000
|
|
|
|
|
b10543748 wrote:
Int32 contador;
ftfy
The second line is pointless.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
A method to try it is written quickly. If the method only contains this declaration, it would work, but also be somewhat useless. Then add a single line that uses the variable and see what the compiler says
The second line is not pointless at all, at least if you intend to use the variable. If not, why declare it in the first place?
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Sorry, I was misreading it. Int32 is an object type and so does need to be initialised in code; I was thinking of value type int s
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Int32 is a struct, not a class, making it a value type and not a reference type. It's also the underlying type in the framework for int, as far as I know you can use them synonymously.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
Well, actually, we don't know... it could be an Acme.Int32, the provided code doesn't specify.
|
|
|
|
|
True. In that case it would be a horror. Using a class or a struct with the name of a type defined in the framework without fully qualifiying the type to point out that it is not the type you would normally assume it to be, is downright deceptive. To be able to do that you also have to leave out the system namespace where the type in question is located and only use the namespace where the 'Acme' type is located. Include both and you have no choice but to fully qualify the types in your code.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
I have just made this code up to show how horrific you can make it
Define my own type using a name defined in the framework
namespace Dummy
{
public class Int32
{
public Int32()
{
}
public string Value
{
get;
set;
}
}
}
Implement it somewhere
using system = Dummy;
namespace AnotherDummy
{
public class Class1
{
public Class1()
{
string value = "Hello";
system.Int32 x = new system.Int32();
x.Value = value;
}
}
}
|
|
|
|
|
Long ago we did our best to write misleading code with help of the C preprocessor. Then Java came along and they celebrated the end of such malicious practices. C# has a preprocessor (as all directives beginning with '#' clearly show), but it is harder to use in a destructive way. Still, your example shows that it was not the preprocessor that was the root of all evil.
And from the clouds a mighty voice spoke: "Smile and be happy, for it could come worse!"
And I smiled and was happy And it came worse.
|
|
|
|
|
That's bad, but it can be worse:
namespace Dummy
{
public struct Int32
{
int val;
private Int32(int v)
{
val = v;
}
public static implicit operator Int32(int x)
{
return new Int32(x - 3);
}
public static implicit operator int(Int32 x)
{
return x.val;
}
public static Int32 operator *(Int32 a, Int32 b)
{
return new Int32(a.val * (b.val + 1));
}
}
}
|
|
|
|
|
+5 - That's just plain awful
|
|
|
|
|
It isn't, as noted, but it also wouldn't matter if it were. Local variables of reference types also "have to" be initialized. That is, they must satisfy the Definite Assignment rules.
If it were a field in a struct/class or an array-element it wouldn't have to be initialized, but that is the case for any type; they're always set to default(type) in those cases.
|
|
|
|
|
int is a C# alias for the CLR type Int32, both refer to the same (value) type. You're thinking of Java's Integer and friends. And even with a reference class, you can't use a local variable before it's been explicitly assigned.
|
|
|
|
|
b10543748 wrote: a store procedure with +/- 2600 lines.
That's the real horror here. It gives me goose bumps just to think about it.
b10543748 wrote: Int32 contador;
contador = (Int32)0;
I think that deserves the hall of shame, just for the fact that the person that wrote this probably had no idea what he was doing. But, what if, historically this code looked like this:
Int32 contador;
contador = (Int32)3.2;
And then, for whatever reason it was change to 0 and the cast was just kept.
Or even:
long outroContador = paramX * 1000000L;
.
.
.
Int32 contador;
contador = (Int32)outroContador;
So, maybe, just maybe, it was just a matter of safety.
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
|
|
|
|
|
b10543748 wrote: and a store procedure with +/- 2600 lines.
I assume you are talking SQL. I haven't counted lines, but I've had printouts of over 45 pages. Personally, if your sproc prints out more than 5 pages, you've screwed up the design. At least in an OLTP environment. (I've never said anything like that to my employer, I'll just think it.)
|
|
|
|
|
Our application uses SQL Server 2005 Express for a couple small data bases. I was adding logic to our migration app (moves the product from one machine to another) to backup the data bases. The simplest way to do this was to spawn SQLCMD to execute a backup command:
BACKUP DATABASE CPT TO DISK='C:\...\FILE.BAK' It worked fine at the command line, producing a nice backup file I could then include in the migration data. Spawning SQLCMD from my migration tool was another story however. The command created the backup file, which my app would then get an 'access denied' error. The file exists in the path I specified, and is the right size. Right-click, Properties, select the Security tab, and I get a message that I'm not allowed to view the security properties of the file unless I take ownership of it.
What. The. F***.
As closely as I can tell, when SQLCMD is run from a command window, it tells the SQL service to create the backup file with administrator access. If SQLCMD is run from another process, the SQL service creates the backup file under the account it's running under, usually Network Service. In other words, it creates a file for you that you can't use.
After much cursing, Googling, a brief foray into the MSDN, and stifling the urge to e-mail a pocket nuke to Redmond, I discovered the solution. If you create the backup file yourself (with zero length), SQL Server will go ahead and 'append' to the existing file, leaving the file ownership and security settings alone. Adding two lines of code, a call to CreateFile() and one to CloseHandle() fixed the problem.
What pisses me off about this is that, since they clearly know how to set the file ownership properly when the command is run interactively, why not do it all the time? Isn't is harder to screw this up than it is to do it right?
Software Zen: delete this;
|
|
|
|
|
You are forgetting something: MS is "customer focussed". As in, MS likes to "foc" it's customers in the "uss" as much as it can...
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The least they could do is take me out to dinner and a movie first.
Software Zen: delete this;
|
|
|
|
|
I'd rather not have them "foc" me in the "uss" and they can keep their dinner.
Ego non sum semper iustus tamen Ego sum nunquam nefas!
|
|
|
|
|
I think, there is no need for comment
private static void DoSplash()
{
SplashScreen sp = new SplashScreen();
sp.ShowDialog();
while (true)
{
Thread.Sleep(200);
}
}
|
|
|
|
|
|
|
That will definitely show a splash screen and make sure it stays around long enough for people to see it.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Ohhh... but that we don't know. We can't see what the other threads, if any, are doing with windows popping up...
Time you enjoy wasting is not wasted time - Bertrand Russel
|
|
|
|