weixin_39682940
2020-12-09 09:11 阅读 1

Opcode: Ceil

For what reason was the support of the opcode 'ceil' disabled?

It's not very convenient to use a macro to round up...

该提问来源于开源项目:phobos2077/sfall

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • weixin_39942488 weixin_39942488 2020-12-09 09:11

    From extra.c in sslc:

    // ceil function temporarily disabled because vanilla "floor" function works incorrectly with negative values

    点赞 评论 复制链接分享
  • weixin_39682940 weixin_39682940 2020-12-09 09:11

    Why can't use the function с++ 'floor', instead of a engine 'floor'?

    点赞 评论 复制链接分享
  • weixin_39997253 weixin_39997253 2020-12-09 09:11

    Why cannot use the function с++ 'floor', instead of a engine 'floor'?

    The answer is simple - it is vanilla function and if you change it, you risk breaking some of the existing scripts. The same situation as with function to get item in NPC inactive hand :)

    点赞 评论 复制链接分享
  • weixin_39682940 weixin_39682940 2020-12-09 09:11

    Round тоже функция движка?

    Ладно будем использовать процедуру из твоих .h библиотек, в принцепи процедурой это получается так же удобно как и функцией.

    点赞 评论 复制链接分享
  • weixin_39682940 weixin_39682940 2020-12-09 09:11

    ceil function temporarily disabled because vanilla "floor"

    Возвращаясь данной к функции, хотелось бы узнать каким образом движковая функция 'floor' относится к функции 'ceil' из с++ ?

    ctx.setReturn(static_cast<int>(ceil(ctx.arg(0).asFloat()))); Вот здесь в коде используется встроенная функция 'ceil' из языка С++, и никаким образом это не связано с выше упомянутой движковой функцией 'floor'

    Я у себя в компиляторе включил использование функции 'ceil', и не наблюдаю никаких ошибок в ее использовании.

    点赞 评论 复制链接分享
  • weixin_39942488 weixin_39942488 2020-12-09 09:11

    I think the reason about vanilla "floor" is its inconsistency. The vanilla "floor" works exactly the same as "ceil" for negative value (and that also makes the ceil marco in lib.math.h return incorrect negative values). It's actually more like "trunc" in C++ instead of ordinary "floor".

    While enabling the new and proper "ceil" function doesn't effect the functionality of vanilla "floor", the results would make people confused. Because in common programming languages floor&ceil should be a pair, but it's not what we got in SSL when the value is negative.

    点赞 评论 复制链接分享
  • weixin_39682940 weixin_39682940 2020-12-09 09:11

    While enabling the new and proper "ceil" function doesn't effect the functionality of vanilla "floor", the results would make people confused.

    I do not quite understand how the result of 'ceil' can confuse people? :) Especially if vanilla 'floor' works like 'trunc', then need to add an additional(correct) function 'sfall_floor' - then there will be a correct pair of 'floor & ceil'.

    点赞 评论 复制链接分享
  • weixin_39942488 weixin_39942488 2020-12-09 09:11

    OK, I've added a "floor2" function similar to how phobos added critter_inven_obj2. ceil will be enabled in sslc and int2ssl.

    点赞 评论 复制链接分享

相关推荐