Skip to main content
edited body
Source Link
user58988
user58988

Axiom, 57 bytes

f(x)==(y:=abs(x);y>9999 or y<0.0001=>"ObjError0001=>"ObjFloatErr 1/x";1";1./x)

test code and results

(21) -> [[i,f(i)] for i in [-2,-1,-0.0001,-0.00001,9999,10000]]
   (21)
   [[- 2.0,- 0.5], [- 1.0,- 1.0], [- 0.0001,- 10000.0],
    [- 0.00001,"ObjError 1/x"], [9999.0,0.0001000100 0100010001],
    [10000.0,"ObjError 1/x"]]

Axiom, 57 bytes

f(x)==(y:=abs(x);y>9999 or y<0.0001=>"ObjError 1/x";1./x)

test code and results

(21) -> [[i,f(i)] for i in [-2,-1,-0.0001,-0.00001,9999,10000]]
   (21)
   [[- 2.0,- 0.5], [- 1.0,- 1.0], [- 0.0001,- 10000.0],
    [- 0.00001,"ObjError 1/x"], [9999.0,0.0001000100 0100010001],
    [10000.0,"ObjError 1/x"]]

Axiom, 57 bytes

f(x)==(y:=abs(x);y>9999 or y<0.0001=>"ObjFloatErr ";1./x)

test code and results

(21) -> [[i,f(i)] for i in [-2,-1,-0.0001,-0.00001,9999,10000]]
   (21)
   [[- 2.0,- 0.5], [- 1.0,- 1.0], [- 0.0001,- 10000.0],
    [- 0.00001,"ObjError 1/x"], [9999.0,0.0001000100 0100010001],
    [10000.0,"ObjError 1/x"]]
added 241 characters in body
Source Link
user58988
user58988

Axiom, 1057 bytes

f(x)==1==(y:=abs(x);y>9999 or y<0.0001=>"ObjError 1/x";1./x)

test code and results

(21) -> [[i,f(i)] for i in [-2,-1,-0.0001,-0.00001,9999,10000]]
   (21)
   [[- 2.0,- 0.5], [- 1.0,- 1.0], [- 0.0001,- 10000.0],
    [- 0.00001,"ObjError 1/x"], [9999.0,0.0001000100 0100010001],
    [10000.0,"ObjError 1/x"]]

The 1. Means 1.0 and x is converted to float even if it is one INT

Axiom, 10 bytes

f(x)==1./x
      

The 1. Means 1.0 and x is converted to float even if it is one INT

Axiom, 57 bytes

f(x)==(y:=abs(x);y>9999 or y<0.0001=>"ObjError 1/x";1./x)

test code and results

(21) -> [[i,f(i)] for i in [-2,-1,-0.0001,-0.00001,9999,10000]]
   (21)
   [[- 2.0,- 0.5], [- 1.0,- 1.0], [- 0.0001,- 10000.0],
    [- 0.00001,"ObjError 1/x"], [9999.0,0.0001000100 0100010001],
    [10000.0,"ObjError 1/x"]]
Source Link
user58988
user58988

Axiom, 10 bytes

f(x)==1./x
      

The 1. Means 1.0 and x is converted to float even if it is one INT