Jump to content

mathematical problem with Int()


Recommended Posts

well, i think my presumption to implement this automatic rounding option could be worth thinking about.

in my script i was using the decimal places like bits: 8.0010010110 in order to save additional data to an integer. the simple integer (8) determines the image to be displayed and the decimal places mark certain individual properties of the image (1 has the specific property, 0 does not). this method seemed very clean to me, because i can save lots of data without defining arrays.

but then it happened what i could not expect: for some reasons the data was false after adding and subtracting 1s and 0s and changing the integer value and i had to look for the error quite a long time (three days). i was really surprised about this floating point problem when i hit it.

so, maybe someone should think about this and maybe there will be added such an option, if someone like me needs "clean math". in this case, when the machine cannot cope with it, it could at least be optionally forced to pretend so.

i agree to your goto opinion in general, in 99% of the cases you can use (though sometimes huge) loops instead. but there are still left some rare cases in which you could use goto very well, e.g. when you want to restart a programm from the very first line. but there is no basic problem in living without goto.

so long j. :-)

btw: i studied physics and math in university and when you want to fly to the moon i tell you better don't leave the results unrounded... :-) to sum it up: there is a difference between math and informatics you find the same differences when you compare math with physics.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

in my script i was using the decimal places like bits: 8.0010010110 in order to save additional data to an integer. the simple integer (8) determines the image to be displayed and the decimal places mark certain individual properties of the image (1 has the specific property, 0 does not). this method seemed very clean to me, because i can save lots of data without defining arrays.

You are creating a data word that contains flags, a very common programming device.

All you have to do is define each flag as a power of 2 instead of 10 - and your problems are solved!

; Flags for attributes
$AttribA = 1
$AttribB = 2
$AttribC = 4
$AttribD = 8
$AttribE = 16
$AttribF = 32
$AttribG = 64
$AttribH = 128

; Default = 9 which is attributes A and D with no others:
$CurrentAttribs = $AttribA + $AttribD

; Set Attrib F without changing any others
$CurrentAttribs = BitOR($CurrentAttribs, $AttribF)

; Clear Attrib D without changing any others
$CurrentAttribs = BitAND($CurrentAttribs, BitNOT($AttribD))

This works much better than decimal flags because you easily work with individual flags by way of BitAnd() , BitOr(), etc.

You could set or clear an attribute by addition/subtraction, but it all goes haywire if you are re-setting/re-clearing it, because all the other values get unintentionally modified.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hi PsaltyDS,

thank you for that. of course this was my first idea using the dual system in order to add the data to a value, but i decided to use I/O because it's easier to keep an overwiew, and from a different point of view, 8.1 is the same as 8.1, while 8.01 means 8.2, 8.001 8.4, 8.0001 8.8 and so on. and as you say, the other values will not be changed unintentionally when using I/O.

BitAnd(),BitOr() and so on is certainly the right way to calculate binary data. well, now i have made my way with I/O, and i only have to keep in mind better to round the differences (luckily addition is no problem for the artificial brain). though better to me still appears the option to establish a global rule for that (opt()).

and i will be going on stating that 8.01 - 8 results 0.01 or 1x10-² and nothing else in this world as long as you don't lose your common sense and your organic brain. :)

thanx for your help

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

...and from a different point of view, 8.1 is the same as 8.1, while 8.01 means 8.2, 8.001 8.4, 8.0001 8.8 and so on.

You can't have 8 to the left of the decimal place for a binary number. Decimal 8.5 would be 1000.1 in binary (23 + 2-1)

Binary = Decimal

0.1 = 1/2 (0.5)

0.01 = 1/4 (0.25)

0.001 = 1/8 (0.125)

0.0001 = 1/16 (0.0625)

0.00001 = 1/32 (0.03125)

etc.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

yeah, okay, the topic is all about the decimal places without integer, that's what i was referring to. that's why i need

$decimalplaces_of_value=round($value-int($value),15)

but now it gets confusing i think.

j.

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

"Incoming!"

*Boom*

"Return fire!"

*Boom*

- The Kandie Man :)

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

well, i know that i can round the result. but still the result before rounding is wrong. i used this operation in a program and couldn't find this error in several days.

8.0001 - 8 should return 0.0001 without rounding, or not ?

every cheap calculator does it right. (btw: the windows calculator does it, too)

j. :-)

You're kidding us?

You needed to find an error of about 1 part in 10^14 and took several days on it?

Have they got any spare jobs at your place?

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You're kidding us?

You needed to find an error of about 1 part in 10^14 and took several days on it?

Have they got any spare jobs at your place?

I haven't minded the conversation at all. Had to dredge up multi-base math that I haven't thought about since DS 'A' school over 25 years ago.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...