# Returns a random `Float` in `[0.0 .. self[`.
fun rand: Float is extern "kernel_Float_Float_rand_0"
fun hypot_with( b : Float ) : Float is extern "hypotf"
+
+ # Is the float an infinite value
+ # this function returns:
+ #
+ # * 1 if self is positive infinity
+ # * -1 if self is negative infinity
+ # * 0 otherwise
+ fun is_inf: Int do
+ if is_inf_extern then
+ if self < 0.0 then return -1
+ return 1
+ end
+ return 0
+ end
+
+ private fun is_inf_extern: Bool is extern "isinf"
end
redef class Collection[ E ]
# Basic manipulations of strings of characters
module string
+import math
intrude import collection # FIXME should be collection::array
`{
# `self` representation with `nb` digits after the '.'.
fun to_precision(nb: Int): String
do
+ var isinf = self.is_inf
+ if isinf == 1 then
+ return "inf"
+ else if isinf == -1 then
+ return "-inf"
+ end
+
if nb == 0 then return self.to_i.to_s
var f = self
for i in [0..nb[ do f = f * 10.0
--- /dev/null
+1.0
+-1.0
+inf
+-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 1.0 / 1.0
+print 1.0 / -1.0
+print 1.0 / 0.0
+print 1.0 / -0.0