1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License (the "License"). 6# You may not use this file except in compliance with the License. 7# 8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9# or http://www.opensolaris.org/os/licensing. 10# See the License for the specific language governing permissions 11# and limitations under the License. 12# 13# When distributing Covered Code, include this CDDL HEADER in each 14# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15# If applicable, add the following below this CDDL HEADER, with the 16# fields enclosed by brackets "[]" replaced with your own identifying 17# information: Portions Copyright [yyyy] [name of copyright owner] 18# 19# CDDL HEADER END 20# 21 22# 23# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 24# 25 26# 27# This test checks whether the arithmetric function "iszero" is available. 28# 29# This was reported as CR #6777491 ("*ksh93* lacks arithmetric function 30# iszero()"): 31# ------------ snip ------------ 32# ksh93 lacks arithmetric function "iszero()" which limits the ability 33# to classify floating-point values or even correctly match against 34# zero (since IEEE754-1985/2008 floating-point math differs between 35# positive and negaive zero values). 36# Frequency 37# Always 38# Regression 39# No 40# Steps to Reproduce 41# $ ksh93 -c '(( iszero(0) )) && print "0 is a zero"' 42# Expected Result 43# Output to stdout: 44# -- snip -- 45# 0 is a zero 46# -- snip -- 47# Actual Result 48# ksh93 exists with: 49# -- snip -- 50# ksh93: iszero(0) : unknown function 51# -- snip -- 52# Error Message(s) 53# ksh93: iszero(0) : unknown function 54# Test Case 55# ksh93 -c '(( iszero(0) )) && print "0 is a zero"' 56# ------------ snip ------------ 57# 58 59# test setup 60function err_exit 61{ 62 print -u2 -n "\t" 63 print -u2 -r ${Command}[$1]: "${@:2}" 64 (( Errors < 127 && Errors++ )) 65} 66alias err_exit='err_exit $LINENO' 67 68set -o nounset 69Command=${0##*/} 70integer Errors=0 71 72typeset str 73integer i 74 75typeset -a tests=( 76 '(( iszero(0) )) && print "OK"' 77 '(( iszero(0.) )) && print "OK"' 78 '(( iszero(-0) )) && print "OK"' 79 '(( iszero(-0.) )) && print "OK"' 80 'float n=0. ; (( iszero(n) )) && print "OK"' 81 'float n=+0. ; (( iszero(n) )) && print "OK"' 82 'float n=-0. ; (( iszero(n) )) && print "OK"' 83 'float n=1. ; (( iszero(n) )) || print "OK"' 84 'float n=1. ; (( iszero(n-1.) )) && print "OK"' 85 'float n=-1. ; (( iszero(n+1.) )) && print "OK"' 86) 87 88for (( i=0 ; i < ${#tests[@]} ; i++ )) ; do 89 str="$( $SHELL -o errexit -c "${tests[i]}" 2>&1 )" || err_exit "test $i: returned non-zero exit code $?" 90 [[ "${str}" == "OK" ]] || err_exit "test $i: expected 'OK', got '${str}'" 91done 92 93# tests done 94exit $((Errors)) 95