Jump to content

<number> + <bool> = <type?>


MvGulik
 Share

Recommended Posts

So, what for type should be returned here.

<number> + <bool> = <type?(int32 / int64 / double)>

int32 + bool = ?

number(bool) = ?

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

What do you think it "should" be.

(with perhaps a background reason)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Yes, yes. That's what AutoIt thinks it "should" be.

... Nap time, later ...

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Or what it loosely thinks it should be.

We are talking about loosely typed language are we not.

$var = HWnd(False) + True;
ConsoleWrite("Value: " & $var & @CRLF & "Type: " & VarGetType($var) & @CRLF)

$var = True + HWnd(False);
ConsoleWrite("Value: " & $var & @CRLF & "Type: " & VarGetType($var) & @CRLF)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Or what it loosely thinks it should be.

We are talking about loosely typed language are we not.

$var = HWnd(False) + True;
ConsoleWrite("Value: " & $var & @CRLF & "Type: " & VarGetType($var) & @CRLF)

$var = True + HWnd(False);
ConsoleWrite("Value: " & $var & @CRLF & "Type: " & VarGetType($var) & @CRLF)

Not sure what's on your mind here, but its a nice case were the order of types is significant.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Anyway:

I think in case of autoit it makes more sense if a bool (or other keyword) would be a int instead of a double/float when automatically converted to a number. Mainly because:

- double/float's are slower in math operation.

- double/float take precedence over int's in math operations.

Or, having a double type introduced (by default autoit means) in what generally are int-type calculations seems wrong to me.

In the Number(Bool/Keyword) case, which is also returning a double. Its kinda opposite to what the Number() documentation suggests.

Remarks: (Number())

If you pass number, function outputs the input.

A string beginning with letters has a numeric value of zero. A string beginning with digits has non-numeric characters stripped.

Default behavior results in auto-sized integer. If input value after conversion is within the range of 32bit integer the result is 32bit integer. If not the result is 64bit integer. Both signed.

Seems that with Number() the Keyword is already converted to a number(double) before Number() gets it as input. Or: "If you pass number, function outputs the input." ergo: Double.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

It makes sense to me.

If you pass two different types into a maths operation, then both should be promoted

to highest native precision type before the calculation is made.

I think the speed you talk of is negligible.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I think the speed you talk of is negligible.

For autoit (0,001%) I guess it is ... .

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Not sure what's on your mind here, but its a nice case were the order of types is significant.

I can understand why adding a 1 to a ptr results in a ptr type. But I don't understand why adding a ptr with value 0 to a 1 results in a double. Seems to me it should be some kind of integer. A bit unexpected. Nothing to do with speed. Just seems uneccesary to promote to double when there's no floating point mentioned n the expression.

Edited by MilesAhead
Link to comment
Share on other sites

But I don't understand why adding a ptr with value 0 to a 1 results in a double.

Because when a bool(keyword) is used in a number context autoit automatically converts its in a number value, of type double/float in this case.

And: (assuming Dev's where using logic I can understand.)

(Number-type + Ptr-type)= number-type (using pointer as additional math parameter)

(Ptr-type + number-type)= Ptr-type (doing math on a pointer)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

This is the one I like

$var = True + True ConsoleWrite("Value: " &amp; $var &amp; @CRLF &amp; "Type: " &amp; VarGetType($var) &amp; @CRLF)
comes up with value "2" type "double" when it should say "2True" or even "too True": to my way of thinking. :)
Do you mean "Double True"?

[Just kidding]

Anyway: I think in case of autoit it makes more sense if a bool (or other keyword) would be a int instead of a double/float when automatically converted to a number.

I second that. Note that it's precisely what is said (albeit implied) in the help file under Language Reference > Datatypes >

If you use arithmetics together with Boolean values (which is not advisable!), the following rules apply:

A Boolean true will be converted into the numeric value 1

A Boolean false will be converted into the numeric value 0

Example:

$Boolean1 = true

$Number1 = 100

$Number2 = $Boolean1 + $Number1

This will result in $Number2 to be the numeric value 101

Notice that the values shown are indeed integers. Double values would be (resp.) 1. 0. 101. or more clearly 1.0 0.0 and 101.0

I can understand why adding a 1 to a ptr results in a ptr type. But I don't understand why adding a ptr with value 0 to a 1 results in a double. Seems to me it should be some kind of integer. A bit unexpected. Nothing to do with speed. Just seems uneccesary to promote to double when there's no floating point mentioned n the exp<b></b>ression.

In this case it isn't promotion, it's demotion!

Not all (exact) integers can be represented exactly as double. Even then, a double value of 1.0 is in fact an abstract representation of an interval of reals whose mapping in the double format gets to 1.0 but there is no such ambiguity with integers.

Because when a bool(keyword) is used in a number context autoit automatically converts its in a number value, of type double/float in this case. And: (assuming Dev's where using logic I can understand.) (Number-type + Ptr-type)= number-type (using pointer as additional math parameter) (Ptr-type + number-type)= Ptr-type (doing math on a pointer)

That's also highly questionable. The order of operands for the addition and multiplication should never impact the result. This is violating a fundamental property of these operations: commutativity. Let alone associativity and distributivity...

I can understand the reasonning behind the scene: since a double is able to represent a broader range of values, let's keep immune to integer overflow by mapping the operation to doubles. This way saves a few cycles but leads to surprising results mentionned in this thread.

That's done at the expense of accuracy.

I would favor an implementation where conversion to double is only done when integral overflow is experienced. That means a few cycles spent for each operation but that would give consistent results and a way for the programmer to notice that an overflow occured (when such things can actually happen and they have significance) by testing VarGetType.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I can understand the reasonning behind the scene: since a double is able to represent a broader range of values, let's keep immune to integer overflow by mapping the operation to doubles.

Mmm. If that is true, and I have a hard time believing that, I think that would be a very bad reason.

As:

- A double/float takes precedence over int.

(as in: introducing a Int-type into a Double-type math operation has no down side(user side). Introducing a Double-type into a Int-type math operation has in my view.)

- It break the general logic that follows from Number(<string>)=int(by default, if applicable)

- And its not AutoIt's job to protect users against logic code/math errors.

*) "I have a hard time believing that": Mmm, feel I'm probably giving some dev's to much credit here.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Yes, yes. That's what AutoIt thinks it "should" be.

i dont even see why your trying.

it do say, and i quote (Boolean values for use in logical expressions.)

and your trying to use it for calculus for god's sake

True is still expression .

its like asking why the hell string 'a'+'1' = 1 and its Double ..,why not = 'a1' and why its not int32 or string?.

If your mixing something that you know it shud not be mix, why are you consirned with results?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

Because when a bool(keyword) is used in a number context autoit automatically converts its in a number value, of type double/float in this case.

So what you're saying is, that's the way it is. Nothing about why it should be that way. I still don't see the point of using doubles unless you have to. A bit weird. It's like in Quick Basic I was getting slow loops unless I remembered to stick "DefInt a-z" at the top. Doing for loops with doubles by default is bizarre.

Link to comment
Share on other sites

Way it is:

0+'1' = 1 {iD} {0xDouble} [0,0]
Number('1') = 1 {I3} (0x00.00.00.01) [0,0] <-- compared to this ...
Number('1', 1) = 1 {I3} (0x00.00.00.01) [0,0]
Number('1', 2) = 1 {I6} (0x00.00.00.00.00.00.00.01) [0,0]
Number('1', 3) = 1 {iD} {0xDouble} [0,0]

0+True = 1 {iD} {0xDouble} [0,0]
Number(True) = 1 {iD} {0xDouble} [0,0] ... <-- this is inconsistent (period), and initial reason for this post.
Number(True, 1) = 1 {I3} (0x00.00.00.01) [0,0]
Number(True, 2) = 1 {I6} (0x00.00.00.00.00.00.00.01) [0,0]
Number(True, 3) = 1 {iD} {0xDouble} [0,0]

Used code. (minus personal debug UDF)

debugout("0+'1'", 0 + '1')
debugout("Number('1')", Number('1'))
debugout("Number('1', 1)", Number('1', 1))
debugout("Number('1', 2)", Number('1', 2))
debugout("Number('1', 3)", Number('1', 3))
debugout("0+True", 0 + True)
debugout("Number(True)", Number(True))
debugout("Number(True, 1)", Number(True, 1))
debugout("Number(True, 2)", Number(True, 2))
debugout("Number(True, 3)", Number(True, 3))

Reason: (for using Double/Float as default type when converting some none number-type to a number type.)

I can understand the reasoning behind the scene: since a double is able to represent a broader range of values, let's keep immune to integer overflow by mapping the operation to doubles.

---

Think #20 post is plenty for this subject, that is resolved as far as I'm concerned.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...