Divide by 0

Forum dedicato ai programmatori di X# in lingua italiana – Italian language forum

Moderator: wriedmann

Post Reply
User avatar
softdevo@tiscali.it
Posts: 189
Joined: Wed Sep 30, 2015 1:30 pm

Divide by 0

Post by softdevo@tiscali.it »

Salve a tutti, dividere 0 per 0 è un errore, ma ho la sensazione che i Runtime di Vulcan gestissero l'errore e restituissero 0, mentre con i Runtime di Xsharp una divisione 0 per 0 restituiscono NaN. Sbaglio?

Grazie
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Divide by 0

Post by Chris »

Hi Danilo,

It is easy to test this, try to compile the following code in vulcan, then in X# with vulcan runtime and then in X# with X# rutnime. In all cases, you should get NaN for both REAL8 and FLOAT, but you will get a System.DivideByZeroException for the INT division.

Apparently that's how it was designed in .Net by MS, to always throw an error in an integer division by 0, but for float numbers it either returns INF (for 123 / 0.0) or NaN (for (0.0 / 0.0).

Code: Select all

FUNCTION Start( ) AS VOID 
	LOCAL r := 0.0 AS REAL8
	LOCAL f := 0.0 AS FLOAT
	LOCAL n := 0 AS INT
	? r/r
	? f/f
	? n/n
RETURN
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply