Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 0.001 = several billion billion?

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Sep 2013 23:00
When I add 0.001 to a value of around 374, the answer I get is out by billions and billions

I extracted the code from my thousands of lines of program, I expected it to behave, but no! You can try it for yourself (Tier 1, beta 18)



The answer is 63285762635192448000000000000000000000.000000

I'm confused, can anyone explain this?

Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 2nd Sep 2013 23:09 Edited at: 2nd Sep 2013 23:09
U found an error!

To work around it, until Paul fixes it:



----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
SoftMotion3D
AGK Developer
19
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 2nd Sep 2013 23:09 Edited at: 2nd Sep 2013 23:10
don't use inc.....lol!

I have no idea sorry...

but I do know the way of math I use works fine

x#=x#+0.001

the error must be tied into the INC command?

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Sep 2013 23:11
Thanks for checking my insanity

It works without the INC method. Unfortunately this is some DBPro code I have converted and it has dozens of INCs

Time to get converting...

Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 2nd Sep 2013 23:17
I found an equally disturbing error...

DEC x#,0.001 turns it into 0.000000

;-p

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 2nd Sep 2013 23:18
Wow! Big interpreter error.

I would never use INC() with floating point numbers.

-- Jim - When is there going to be a release?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Sep 2013 23:23
I have to be honest I never use inc with floats but I assumed it was for integers anyway. What do the docs say? On iPad at the moment...

"Here I am trying to do some good for the world..." - Fluffy Rabbit
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 2nd Sep 2013 23:24
F1 Help:

Quote: "
The inc command will increment a variable by a specified value or by a default of 1. Both integer and real variables can be incremented by either an integer or real value, in addition to array and data type elements.
"


----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Sep 2013 23:44 Edited at: 2nd Sep 2013 23:46
It's all a bit scary. I still don't get the right answer; the last figure here is supposed to be in increments of 0.001, they are out by a factor of 50.

3.831 Object Final position : 10001, 0.000000, 0.000000, 374.743317
3.831 Object Final position : 10002, 0.000000, 0.000000, 374.794312
3.831 Object Final position : 10003, 0.000000, 0.000000, 374.845337


This could be a typed array problem. The value is:

arrHudObject[objIndex].pos.z

where arrHudObject is a typed array containing numerous elements, pos is a type of 3 floats, and z is one of those floats.

Here's the code to show there is no other manipulation going on...


Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Sep 2013 00:52
I didn't think INC supported floats in AppGameKit, because it hasn't exactly worked for me.

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Sep 2013 01:35
I reported something up with the inc/dec commands a while back (v1072).

https://code.google.com/p/agk/issues/detail?id=303

To be honest, Lee's fix didn't make a whole lot of sense to me (I'm probably missing something ).

After that I think I just always used the operators.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Sep 2013 10:03
Hodgey, You reported cause and effect, and he fixed the effect!

i.e You said that because the calculation was so wildly incorrect, it produced huge results that crashed the program. Therefore, he made sure you could display huge results.

I've resubmitted your issue with details on why the previous fix was not valid.

https://code.google.com/p/agk/issues/detail?id=594

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 3rd Sep 2013 10:21
I didn't realize that inc was supposed to work with floats. Been thinking of posting it as a request. I want to use it all the time. I have voted for this issue

Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 3rd Sep 2013 11:43
Quote: "Hodgey, You reported cause and effect, and he fixed the effect!"

That's a good way of putting it.

I hope the cause is fixed this time around. I'll admit, I've become a fan of the +=, -= etc operators. Be nice if AppGameKit supported them.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 3rd Sep 2013 18:03
I just officially confirmed this bug.

I was quite surprised to see that someone is using v1072 (unless that was a typo).

I tested in v1076 and v10818, with the same basic results.

I modified the posted example a bit so that you can see what happens (the original code ran fast and then crashed).



Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 3rd Sep 2013 18:18
Quote: "I was quite surprised to see that someone is using v1072 (unless that was a typo)."


My mistake, I copied Hodgey's original issue from early 2012 without changing the version.

Thanks for verifying

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Sep 2013 02:53
I know we're probably talking fractions of a clock cycle here, but would there be any speed difference between using INC versus a = a+1?

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 5th Sep 2013 16:21
I suspect not an awful lot.

In either case, at the assembly language level, the contents of a location are loaded into the accumulator register and a value is added to it. Then the contents of the register are stored in another location (which happens to be the same as the source location). Potentially, there are two sets of address calls (I can't remember the proper techincalish terms right now) in the non-inc version versus one address call in the INC version.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Sep 2013 15:45
I'd have said the non inc version would be quicker as it doesn't have a function call to process.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Sep 2013 16:37
'INC' is actually an assembly level command and the compiler would probably compile the code that way if the target and increment values are integers.

In both cases, if the values were floats, a different set of registers and commands are used. But the code would probably compile down to the same set of assembly level commands.

Actually, the compiler compiles down to machine level commands that can be represented by assembly language code. In Tier 2, this gets done right off.

For Tier 1, the AppGameKit compiler turns the Basic into a byte code that the interpreter then interprets. The interpreter is compiled down to machine level and, upon execution, reads the byte code and does the appropriate stuff. So, in that case, the 'INC' is a function call for Tier 1.

All of this is pure conjecture on my part.

And I just looked at the interpreter.cpp file. If you go down to about line 1952 (v10818), you can see how the interpreter handles some of the commands. Interestingly, the first set of commands in the switch are for the INC command. And it is set up to handle all sorts of combinations of variable/value types. Pretty neat!

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Sep 2013 16:50 Edited at: 6th Sep 2013 18:20
Delphi's INC is faster than C++ in tests I have seen.

It's NOT a function call - it's a compiler operation. In fact, for integer values on X86 processors it's one instruction:

inc DWORD PTR [var]

For an increment with a constant value it's not quite as fast, but still fast:

add BYTE PTR [var], 10

Using a variable parameter as the second argument is much slower, because it requires an additional memory fetch.

A bytecode runtime system is obviously going to be magnitudes slower. If you want to do intensive calculations (for example, on audio) you really do need to use a native compiler (T2/3).

Incidentally, Pascal's INC only works with ordinal variables (cardinal, integer, enumerated, char). I haven't seen a floating point version of it - but maybe it's there in APL!

-- Jim - When is there going to be a release?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Sep 2013 17:07
Quote: "Delphi's INC is faster than C++ in tests I have seen."

I think it all comes down to the efficiency of the compiler.

Have you tested against multiple C++ environments? Just curious.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Sep 2013 18:03
AL - I didn't do any tests - but I did read some reports. VC++ is not, in my experience, the most efficient compiler for time-critical code.

I'm going to tell a boring story, so please all feel free to pass on and go for a drink!

Commodore UK passed me on to Pearson New Entertainment, who wanted a DJ Mix program called Music Machine. I'd programmed boring PC stuff, but not the really good stuff on the Amiga. To mix virtual instruments in real-time on up to 16 channels on really rubbish hardware I needed the most efficient compiler I could find.

This turned out to be XDS Oberon-2(*) from a bunch of guys and girls in Siberia. They used to program space missions, so they knew all about secure code. They were great. They added optimisation when I sent them examples of what I was doing. It worked - and still works!

It seems to me that for the majority of programming the compiler efficiency doesn't really matter that much. But it does for music, video and games.

* Oberon-2 - A successor to Pascal designed by Niklaus Wirth at ETH in Zurich. Very elegant stripped-down object-orientated language. See:
http://en.wikipedia.org/wiki/Niklaus_Wirth

-- Jim - When is there going to be a release?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Sep 2013 18:16
Yup, a good man is Niklaus Wirth. I think his book "Algorithms + Data Structures = Programs" was one that I had in my Pascal programming class at UT.

Pascal was the first language (in 1979) after Fortran and Assembler that I was introduced to. And I loved it, thinking that I had finally found something that let me do everything Fortran wouldn't. Much later, when I was programming for myself, I used Turbo Pascal because of cost and availability and had a lot of fun. I haven't worked with Pascal since I joined the OOP world (about 1991), but, when I finally have some time after my current projects, I look forward to playing with it again.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 6th Sep 2013 18:44
AL - I guess we're stepping outside the thread to continue the discussion too far. Turbo Pascal and Modula-2 made a vast difference to PC development, and contributed to the success of the PC.

I think you'll find, when you have time to play, that Object Pascal is cleaner and nicer than C++. Dot h files - forget! Loads of casts - forget.

Wirth seems still to be alive at the age of 79. Hurray!

-- Jim - When is there going to be a release?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Sep 2013 19:06
Quote: "I guess we're stepping outside the thread to continue the discussion too far."

Correct. My apologies BatVink. We do get carried away sometimes.

Paul has indicated that this fix will be in for V2.

So, in the meantime, I guess we use the full equation.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Scary Little Rabbit
15
Years of Service
User Offline
Joined: 4th Aug 2009
Location: Chelyabinsk, Russian Federation.
Posted: 7th Sep 2013 20:07
Quote: "We do get carried away sometimes."
love that. it is very interesting when experienced are talking.

error #1:
"too many stars, too many stares. disembody."
WIP: MIND!! | free fonts for your AGKs
MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 7th Sep 2013 20:57
but at the end of the very interesting story, will it be considered a bug to be solved in a beta20 or not. In my opinion, INC-DEC commands, despite help, should be limited to integer and to be more "taliban", I think that they be should be used only for +1 and -1 inc/dec , as in Assembler stuff. From a C/C++ point of view, this turns into

that is what the interpreter should do if it meets

Otherwise, let's prepare for a bunch of new betas! Oh my God!
MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 8th Sep 2013 22:41
I checked today with a little sample code, and I have verified that INC/DEC with decimal values as 0.1 or 0.01, outputs erratical results. USE ONLY WITH INTEGERS
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 9th Sep 2013 00:46
I think that trying to use INC and DEC with floating point numbers should be illegal and produce an error.

-- Jim - When is there going to be a release?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Sep 2013 01:25
I don't think I've ever seen any language that allows INC/DEC with floats.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
AgentSam
12
Years of Service
User Offline
Joined: 14th Mar 2012
Location: Virtual Space
Posted: 9th Sep 2013 14:31
Let us give a moments pause to think about the best solution...

Should we limit INC/DEC to integers, or to make it work with floats also.

I feel it is likely that new coders will try to use it with floats, so instead of having everyone stumble on the "works with integers only" problem - make it work with floats too. (We're not trying to reinvent assembly language here, so the comparison is pretty far off.)

In any case, Paul has already marked the issue as accepted, and commented "Will be fixed as part of version 2".

By the way - I've recently begun to see the following message on the AppGameKit issues list:
"Issue attachment storage quota exceeded."

Is this indicative that some action needs to be taken to allocate more space - or delete some of the past issues marked as fixed (ouch, they were useful in their own right).

Cheers,
AgentSam
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Sep 2013 14:36
Quote: "I feel it is likely that new coders will try to use it with floats, so instead of having everyone stumble on the "works with integers only" problem - make it work with floats too. (We're not trying to reinvent assembly language here, so the comparison is pretty far off.)"


I would agree with this statement, as my reason for raising the topic is that I converted DBP code to AppGameKit, and it failed. DBP migrators will no doubt stumble on the same issue.

At compiled level, it may mean extra instructions to separate out integers and floats into different processes, which has efficiency issues. In which case can this be dealt with at precompiler stage? an INC/DEC of a float would be recoded in the precompiler.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th Sep 2013 14:50
I agree too, it's not a big ask for inc and dec to work with floats. I don't normally work that way either but I see no reason why it would be unexpected usage of the commands. Particularly as they are described as working for floats in the docs.

I'm pretty sure Paul would see it that way too.

"Everything should be made as simple as possible, but not simpler."
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 9th Sep 2013 15:24
Okay - If you really want this mess, how are overflows going to be handled? Floats may be differently handled on different processors, and have to be dealt with very carefully. I foresee many an apparently inexplicable program detonation.

-- Jim - When is there going to be a release?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Sep 2013 15:34 Edited at: 9th Sep 2013 15:35
Quote: "Okay - If you really want this mess, how are overflows going to be handled? Floats may be differently handled on different processors, and have to be dealt with very carefully. I foresee many an apparently inexplicable program detonation."


I think it's important to differentiate an AppGameKit INC from a machine code INC. All we are asking for (I think) is that

INC myVal#, 0.1

does the same as

MyVal# = MyVal# + 0.1

The compiler/interpreter can handle this in whatever way is necessary. Different handling on different processors will result in exactly the same result for that machine, irrespective of which coding syntax you choose.

I hope that makes sense

MarcoBruti
13
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 9th Sep 2013 17:06
Quote: "I hope that makes sense"

It makes sense only for retro-compatibility with DB Pro.
I bet that very few programmers with yearly experience with ASM, C, C++, etc, will use INC or DEC with floats.
Moreover, the

syntax in place of

is not very elegant.
The shortened way, used in C, is much more elegant.

Maybe we could add a the shortened syntax to T1.
Anyway TGC may do as they please, these are only recommendations by a guy with 30 years experience in ICT.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Sep 2013 17:10
If you look at interpreter.cpp, you can see how it handles things. It allows for a lot of cases in the INC command:


The issue, I suppose, is whether the values in the line are being recognized properly for the types that they are.

If you use simply INC or DEC with a float variable, it works perfectly. It is when you try adding any INC/DEC value, regardless of type (float var, constant float, constant int) that it barfs up. This seems to imply that it is, possibly, the correct recogniztion of type of value/variable and selection of the correct instruction.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 10th Sep 2013 00:28 Edited at: 10th Sep 2013 00:32
Well this is an interesting glitch. AL I think you're right about the problem. It looks to me like the interpreter is simply treating the floating points as ints for the increment operation and then returning a float. For example:



displays as 170141183460469230000000000000000000000.000000

1.0(Dec) as a 32 bit floating point = 3F800000(Hex) = 00111111 10000000 00000000 00000000(Bin)
3F800000(Hex) as a 32 bit signed integer = 1065353216(Dec)
1065353216(Dec) + 1065353216(Dec) = 2130706432(Dec)
2130706432(Dec) = 7F000000(Hex) = 01111111 00000000 00000000 00000000(Bin)
7F000000(Hex) interpreted as a 32 bit floating point = 170141183460469231731687303716000000000(Dec)
and we're back to where we started (albeit with greater precision).

Quote: "Will be fixed as part of version 2"

I wonder why not in V1.. After all, surely the solution as other people have said is just to implement it in C++ as



Anyhow whatever is decided, clearly it is not acceptable as is. If floats are not to be supported, the compiler should throw an error in the same way as it would for




Quote: "I bet that very few programmers with yearly experience with ASM, C, C++, etc, will use INC or DEC with floats.
... these are only recommendations by a guy with 30 years experience in ICT."

I'm sure you're right, but I'm afraid the predicted behaviour of an experienced ASM/C/C++ programmer with 30 years experience is largely irrelevant in a language aimed at helping beginners to produce the games they always wanted. Beginners are sure to blunder into this mistake, especially given that it is supposed to be supported in the documentation (which beginners may actually read) and given that it apparently works in DBP. TGC do need to fix this, one way or the other, and in my opinion floats should be supported. A high level BASIC dialect shouldn't be making us worry about data types more than we really have to. Leave that for veteran C++ programmers!

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Sep 2013 01:27
Lucas - I'm afraid I can't agree about some of that. We should not expose new programmers to inexplicable errors. Those will result from floating-point overflow, and may on some systems throw a serious unhandled exception and crash.

I utterly disagree that Basic should let us ignore data types. These are fundamental. That's part of the problem with loose typing - you're expected to know what you are doing.

-- Jim - When is there going to be a release?
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 10th Sep 2013 04:35
This has become an interesting discussion. I agree that INC/DEC should support floats.

Quote: "After all, surely the solution as other people have said is just to implement it in C++ as"

Not to get too technical Lucas but the INC / DEC commands are probably closer to:



Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 10th Sep 2013 05:06
If we were coding things directly, yup, something like that.

The tricky thing is that the interpreter is taking a compiled byte code file and basing its actions on what the compiler said the command was to start with. Then it is being applied to a char* stack of stuff that they need to extract the variables out of.

There are a few places it could fall down if something isn't quite right. And, as we've all had happen to us, it only takes one flippin' character to mess up everything.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 10th Sep 2013 09:44
Quote: "We should not expose new programmers to inexplicable errors. Those will result from floating-point overflow"

Sorry I think I'm probably missing the point here. Will a floating-point overflow in an inc command be any different to one caused by regular variable addition?

@Hodgey
Fair point!

@AL
Yes you're probably right, I've no experience with writing interpreters so I don't really know what's involved. I guess I'm just surprised that it is a difficult task as I would just have though it was a question of casting those bytes on the stack to float instead of int. Anyhow, as it's on TGC's radar to fix, I'm fine with that .

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Sep 2013 11:41 Edited at: 10th Sep 2013 11:42
How is there any more chance of floating point overflow using inc than using standard addition?

inc flt#, 100.0

is exactly the same as

flt# = flt# + 100.0

If either one takes the flt# variable over the highest possible value in AppGameKit it is handled (or not) in the same way internally, surely?

We're not asking for the engine to be changed, just the way it handles inc. Imagine we are asking for a new overload for a command called add(int) so it can handle floats.

In basic this might be (original command):

And the overload might be:


Edit: I missed page 2 of this discussion, looks like I was beaten to it

"Everything should be made as simple as possible, but not simpler."

Login to post a reply

Server time is: 2024-11-24 19:43:04
Your offset time is: 2024-11-24 19:43:04