# PureBasic Forum

 It is currently Sun Apr 22, 2018 7:28 am

 All times are UTC + 1 hour

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Float/double division by 0 causes invalid memory accessPosted: Wed Apr 04, 2018 2:38 pm

Joined: Fri Jan 21, 2011 8:25 am
Posts: 1018
Location: 'stralia!
Hi

Dividing a float constant by a float variable (or double) that happens to be 0 causes an invalid memory access.
If the left hand operand is a variable as well, the result is +Infinity as expected.

This seems to be related to the debugger as the correct result is shown in release mode.

Code:

Define x.d = 10
Define y.d = 0

y = x / y ; Works correctly.
MessageRequester("", StrF(y))

Define a.d = 0
a = 1.0 / a ; Invalid memory access.

MessageRequester("", StrF(a))

_________________

Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds

Top

 Post subject: Re: Float/double division by 0 causes invalid memory accessPosted: Thu Apr 05, 2018 3:01 pm
 User

Joined: Sat Sep 02, 2017 7:30 pm
Posts: 47

Last edited by PedroMartins on Fri Apr 06, 2018 2:20 pm, edited 1 time in total.

Top

 Post subject: Re: Float/double division by 0 causes invalid memory accessPosted: Thu Apr 05, 2018 4:01 pm
 Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 382
I think it's because devision by 0. This is not possible.

Code:
Define a.d = 0

if a
a = 1.0 / a ; Invalid memory access.
endif

MessageRequester("", StrD(a))

Top

 Post subject: Re: Float/double division by 0 causes invalid memory accessPosted: Thu Apr 05, 2018 4:11 pm
 Enthusiast

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 651
Shield wrote:
Hi

Dividing a float constant by a float variable (or double) that happens to be 0 causes an invalid memory access.
If the left hand operand is a variable as well, the result is +Infinity as expected.

This seems to be related to the debugger as the correct result is shown in release mode.

It's the same on Windows. I think, there is nothing to discuss. It's a bug in the debugger.

_________________

Top

 Post subject: Re: Float/double division by 0 causes invalid memory accessPosted: Thu Apr 05, 2018 5:04 pm

Joined: Fri Jan 21, 2011 8:25 am
Posts: 1018
Location: 'stralia!
@PedroMartins:
This was just an oversight on my part. I tested with floats first and then doubles but forgot to switch StrF().
It's not working either way.

@Wolfram:
Division by zero is perfectly valid and well-defined with floating point data types,
so that's not the issue here either.

@Josh:
Yep.

_________________

Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite