fun rand: Float is extern "kernel_Float_Float_rand_0"
fun hypot_with( b : Float ) : Float is extern "hypotf"
+ fun is_nan: Bool is extern "isnan"
+
# Is the float an infinite value
# this function returns:
#
# Pretty print self, print needoed decimals up to a max of 3.
redef fun to_s do
var str = to_precision( 3 )
- if is_inf != 0 then return str
+ if is_inf != 0 or is_nan then return str
var len = str.length
for i in [0..len-1] do
var j = len-1-i
# `self` representation with `nb` digits after the '.'.
fun to_precision(nb: Int): String
do
+ if is_nan then return "nan"
+
var isinf = self.is_inf
if isinf == 1 then
return "inf"
--- /dev/null
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2004-2008 Jean Privat <jean@pryen.org>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+print 0.0 / 1.0
+print 0.0 / 0.0
+print 0.0 / -0.0
+print ((-1.0).sqrt)